From 0ea458b4dc9241a59fd18456c846be44694fdb7d Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 18:00:42 -0600 Subject: [PATCH 01/26] Add functions for converting between UTF-8/16. --- Source/Core/Common/Src/StringUtil.cpp | 34 +++++++++++++++++++++++++++ Source/Core/Common/Src/StringUtil.h | 7 ++++++ 2 files changed, 41 insertions(+) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 6ef3d91a73..503c2810c3 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -22,6 +22,10 @@ #include "CommonPaths.h" #include "StringUtil.h" +#ifdef _WIN32 +#include +#endif + // faster than sscanf bool AsciiToHex(const char* _szValue, u32& result) { @@ -375,3 +379,33 @@ 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 UTF8ToUTF16(const std::string& input) +{ + auto const size = MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), nullptr, 0); + + std::wstring output; + output.resize(size); + + if (size != MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), &output[0], output.size())) + output.clear(); + + return output; +} + +#endif diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index 102ae2d5fb..4e02ce4506 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -97,4 +97,11 @@ 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); +#ifdef _WIN32 + +std::string UTF16ToUTF8(const std::wstring& str); +std::wstring UTF8ToUTF16(const std::string& str); + +#endif + #endif // _STRINGUTIL_H_ From ea75577278d818e4d3cb3b6db329017df69df00f Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 18:01:48 -0600 Subject: [PATCH 02/26] Use the new UTF-16 conversion function in two places. --- .../Src/ControllerInterface/DInput/DInput.cpp | 16 +++++----------- Source/Plugins/Plugin_VideoDX11/Src/main.cpp | 6 ++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp index c23e9df17e..01baf9cf1a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp @@ -4,7 +4,7 @@ #include "DInput.h" -#include +#include "StringUtil.h" #ifdef CIFACE_USE_DINPUT_JOYSTICK #include "DInputJoystick.h" @@ -41,24 +41,18 @@ BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device) { - std::string out; - - DIPROPSTRING str; - ZeroMemory(&str, sizeof(str)); + DIPROPSTRING str = {}; str.diph.dwSize = sizeof(str); str.diph.dwHeaderSize = sizeof(str.diph); str.diph.dwHow = DIPH_DEVICE; + std::string result; if (SUCCEEDED(device->GetProperty(DIPROP_PRODUCTNAME, &str.diph))) { - const int size = WideCharToMultiByte(CP_UTF8, 0, str.wsz, -1, NULL, 0, NULL, NULL); - char* const data = new char[size]; - if (size == WideCharToMultiByte(CP_UTF8, 0, str.wsz, -1, data, size, NULL, NULL)) - out.assign(data); - delete[] data; + result = StripSpaces(UTF16ToUTF8(str.wsz)); } - return StripSpaces(out); + return result; } void Init(std::vector& devices, HWND hwnd) diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index b7dd9101d3..512f70eaa7 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -102,15 +102,13 @@ void InitBackendInfo() if (FAILED(hr)) PanicAlert("Failed to create IDXGIFactory object"); - char tmpstr[512] = {}; - DXGI_ADAPTER_DESC desc; // adapters g_Config.backend_info.Adapters.clear(); g_Config.backend_info.AAModes.clear(); while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND) { + DXGI_ADAPTER_DESC desc; ad->GetDesc(&desc); - WideCharToMultiByte(/*CP_UTF8*/CP_ACP, 0, desc.Description, -1, tmpstr, 512, 0, false); // TODO: These don't get updated on adapter change, yet if (g_Config.backend_info.Adapters.size() == g_Config.iAdapter) @@ -127,7 +125,7 @@ void InitBackendInfo() } } - g_Config.backend_info.Adapters.push_back(tmpstr); + g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description)); ad->Release(); } From 69f7671ee8184b109d801243707116eb1a5cba56 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 18:51:02 -0600 Subject: [PATCH 03/26] Fix "Common" to build with "Unicode" project setting. --- Source/Core/Common/Common.vcxproj | 4 +- Source/Core/Common/Src/CDUtils.cpp | 11 ++--- Source/Core/Common/Src/ConsoleListener.cpp | 4 +- Source/Core/Common/Src/ExtendedTrace.cpp | 52 +++++++++------------- Source/Core/Common/Src/ExtendedTrace.h | 9 ++-- Source/Core/Common/Src/FileSearch.cpp | 5 +-- Source/Core/Common/Src/FileUtil.cpp | 19 ++++---- Source/Core/Common/Src/Misc.cpp | 2 +- Source/Core/Common/Src/MsgHandler.cpp | 2 +- Source/Core/Common/Src/StringUtil.h | 14 ++++++ 10 files changed, 63 insertions(+), 59 deletions(-) diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 626a4df909..822fafe74b 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -44,7 +44,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary @@ -54,7 +54,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary diff --git a/Source/Core/Common/Src/CDUtils.cpp b/Source/Core/Common/Src/CDUtils.cpp index 42aa9bfe34..9a302b9189 100644 --- a/Source/Core/Common/Src/CDUtils.cpp +++ b/Source/Core/Common/Src/CDUtils.cpp @@ -6,6 +6,7 @@ #include // for std::unique_ptr #ifdef _WIN32 #include +#include "StringUtil.h" #elif __APPLE__ #include #include @@ -25,7 +26,7 @@ #ifdef _WIN32 // takes a root drive path, returns true if it is a cdrom drive -bool is_cdrom(const char drive[]) +bool is_cdrom(const TCHAR* drive) { return (DRIVE_CDROM == GetDriveType(drive)); } @@ -36,15 +37,15 @@ std::vector cdio_get_devices() std::vector drives; const DWORD buffsize = GetLogicalDriveStrings(0, NULL); - std::unique_ptr buff(new char[buffsize]); - if (GetLogicalDriveStrings(buffsize, buff.get()) == buffsize - 1) + std::vector buff(buffsize); + if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1) { - const char* drive = buff.get(); + auto drive = buff.data(); while (*drive) { if (is_cdrom(drive)) { - std::string str(drive); + std::string str(TStrToUTF8(drive)); str.pop_back(); // we don't want the final backslash drives.push_back(std::move(str)); } diff --git a/Source/Core/Common/Src/ConsoleListener.cpp b/Source/Core/Common/Src/ConsoleListener.cpp index cf03581431..5a4ff126bf 100644 --- a/Source/Core/Common/Src/ConsoleListener.cpp +++ b/Source/Core/Common/Src/ConsoleListener.cpp @@ -61,7 +61,7 @@ void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title // Save the window handle that AllocConsole() created hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Set the console window title - SetConsoleTitle(Title); + SetConsoleTitle(UTF8ToTStr(Title).c_str()); // Set letter space LetterSpace(80, 4000); //MoveWindow(GetConsoleWindow(), 200,200, 800,800, true); @@ -195,7 +195,7 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool static const int MAX_BYTES = 1024 * 16; - std::vector> Str; + std::vector> Str; std::vector> Attr; // ReadConsoleOutputAttribute seems to have a limit at this level diff --git a/Source/Core/Common/Src/ExtendedTrace.cpp b/Source/Core/Common/Src/ExtendedTrace.cpp index 3fe661f2e4..85057639a5 100644 --- a/Source/Core/Common/Src/ExtendedTrace.cpp +++ b/Source/Core/Common/Src/ExtendedTrace.cpp @@ -17,6 +17,7 @@ #include #include #include "ExtendedTrace.h" +#include "StringUtil.h" using namespace std; #include @@ -274,13 +275,21 @@ static BOOL GetSourceInfoFromAddress( UINT address, LPTSTR lpszSourceInfo ) return ret; } -void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file ) +void PrintFunctionAndSourceInfo(FILE* file, const STACKFRAME& callstack) +{ + TCHAR symInfo[BUFFERSIZE] = _T("?"); + TCHAR srcInfo[BUFFERSIZE] = _T("?"); + + GetFunctionInfoFromAddresses((ULONG)callstack.AddrPC.Offset, (ULONG)callstack.AddrFrame.Offset, symInfo); + GetSourceInfoFromAddress((ULONG)callstack.AddrPC.Offset, srcInfo); + etfprint(file, " " + TStrToUTF8(srcInfo) + " : " + TStrToUTF8(symInfo) + "\n"); +} + +void StackTrace( HANDLE hThread, const char* lpszMessage, FILE *file ) { STACKFRAME callStack; BOOL bResult; CONTEXT context; - TCHAR symInfo[BUFFERSIZE] = _T("?"); - TCHAR srcInfo[BUFFERSIZE] = _T("?"); HANDLE hProcess = GetCurrentProcess(); // If it's not this thread, let's suspend it, and resume it at the end @@ -318,9 +327,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file ) etfprint(file, "Call stack info: \n"); etfprint(file, lpszMessage); - GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo ); - GetSourceInfoFromAddress( (ULONG)callStack.AddrPC.Offset, srcInfo ); - etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n")); + PrintFunctionAndSourceInfo(file, callStack); for( ULONG index = 0; ; index++ ) { @@ -341,9 +348,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file ) if( !bResult || callStack.AddrFrame.Offset == 0 ) break; - GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo ); - GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo ); - etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n")); + PrintFunctionAndSourceInfo(file, callStack); } @@ -351,19 +356,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file ) ResumeThread( hThread ); } -void StackTrace( HANDLE hThread, wchar_t const*lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp ) -{ - // TODO: remove when Common builds as unicode - size_t origsize = wcslen(lpszMessage) + 1; - const size_t newsize = 100; - size_t convertedChars = 0; - char nstring[newsize]; - wcstombs_s(&convertedChars, nstring, origsize, lpszMessage, _TRUNCATE); - - StackTrace(hThread, nstring, file, eip, esp, ebp ); -} - -void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp ) +void StackTrace(HANDLE hThread, const char* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp ) { STACKFRAME callStack; BOOL bResult; @@ -391,9 +384,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO etfprint(file, "Call stack info: \n"); etfprint(file, lpszMessage); - GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo ); - GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo ); - etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n")); + PrintFunctionAndSourceInfo(file, callStack); for( ULONG index = 0; ; index++ ) { @@ -414,10 +405,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO if( !bResult || callStack.AddrFrame.Offset == 0 ) break; - GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo ); - GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo ); - etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n")); - + PrintFunctionAndSourceInfo(file, callStack); } if ( hThread != GetCurrentThread() ) @@ -426,7 +414,8 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO char g_uefbuf[2048]; -void etfprintf(FILE *file, const char *format, ...) { +void etfprintf(FILE *file, const char *format, ...) +{ va_list ap; va_start(ap, format); int len = vsprintf(g_uefbuf, format, ap); @@ -434,7 +423,8 @@ void etfprintf(FILE *file, const char *format, ...) { va_end(ap); } -void etfprint(FILE *file, const std::string &text) { +void etfprint(FILE *file, const std::string &text) +{ size_t len = text.length(); fwrite(text.data(), 1, len, file); } diff --git a/Source/Core/Common/Src/ExtendedTrace.h b/Source/Core/Common/Src/ExtendedTrace.h index 12e7ed41fa..003c8a68e3 100644 --- a/Source/Core/Common/Src/ExtendedTrace.h +++ b/Source/Core/Common/Src/ExtendedTrace.h @@ -26,15 +26,14 @@ #define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) InitSymInfo( IniSymbolPath ) #define EXTENDEDTRACEUNINITIALIZE() UninitSymInfo() -#define STACKTRACE(file) StackTrace( GetCurrentThread(), _T(""), file) -#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), _T(""), file, eip, esp, ebp) +#define STACKTRACE(file) StackTrace( GetCurrentThread(), "", file) +#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), "", file, eip, esp, ebp) // class File; BOOL InitSymInfo( PCSTR ); BOOL UninitSymInfo(); -void StackTrace( HANDLE, LPCTSTR, FILE *file); -void StackTrace( HANDLE, LPCTSTR, FILE *file, DWORD eip, DWORD esp, DWORD ebp); -void StackTrace( HANDLE hThread, wchar_t const* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp); +void StackTrace(HANDLE, char const* msg, FILE *file); +void StackTrace(HANDLE, char const* msg, FILE *file, DWORD eip, DWORD esp, DWORD ebp); // functions by Masken void etfprintf(FILE *file, const char *format, ...); diff --git a/Source/Core/Common/Src/FileSearch.cpp b/Source/Core/Common/Src/FileSearch.cpp index 595dfe7000..674cf0e1d5 100644 --- a/Source/Core/Common/Src/FileSearch.cpp +++ b/Source/Core/Common/Src/FileSearch.cpp @@ -51,7 +51,7 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string& BuildCompleteFilename(GCMSearchPath, _strPath, _searchString); #ifdef _WIN32 WIN32_FIND_DATA findData; - HANDLE FindFirst = FindFirstFile(GCMSearchPath.c_str(), &findData); + HANDLE FindFirst = FindFirstFile(UTF8ToTStr(GCMSearchPath).c_str(), &findData); if (FindFirst != INVALID_HANDLE_VALUE) { @@ -62,7 +62,7 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string& if (findData.cFileName[0] != '.') { std::string strFilename; - BuildCompleteFilename(strFilename, _strPath, findData.cFileName); + BuildCompleteFilename(strFilename, _strPath, TStrToUTF8(findData.cFileName)); m_FileNames.push_back(strFilename); } @@ -112,7 +112,6 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string& #endif } - const CFileSearch::XStringVector& CFileSearch::GetFileNames() const { return m_FileNames; diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index f42c204396..b3c2d7c161 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -41,10 +41,11 @@ #include #endif -#include #include #include +#include "StringUtil.h" + #ifndef S_ISDIR #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif @@ -127,7 +128,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()); @@ -149,7 +150,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) @@ -228,7 +229,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) @@ -257,7 +258,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", @@ -413,7 +414,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); @@ -423,7 +424,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; @@ -480,7 +481,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) { @@ -491,7 +492,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()); diff --git a/Source/Core/Common/Src/Misc.cpp b/Source/Core/Common/Src/Misc.cpp index aafe37886f..8364bda48d 100644 --- a/Source/Core/Common/Src/Misc.cpp +++ b/Source/Core/Common/Src/Misc.cpp @@ -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 diff --git a/Source/Core/Common/Src/MsgHandler.cpp b/Source/Core/Common/Src/MsgHandler.cpp index 7c666227aa..283dc72ef1 100644 --- a/Source/Core/Common/Src/MsgHandler.cpp +++ b/Source/Core/Common/Src/MsgHandler.cpp @@ -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); diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index 4e02ce4506..5177bc8ed8 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -102,6 +102,20 @@ std::string UriEncode(const std::string & sSrc); std::string UTF16ToUTF8(const std::wstring& str); 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_ From 65683ebc6494623a7bf0e297522b6912319e3e8c Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 19:43:29 -0600 Subject: [PATCH 04/26] Hopefully fix all filename handling to support Unicode. --- Source/Core/Common/Src/FileUtil.cpp | 48 ++++++++++----------------- Source/Core/Common/Src/SDCardUtil.cpp | 7 ++-- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index b3c2d7c161..78685bbe70 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -82,7 +82,7 @@ bool Exists(const std::string &filename) std::string copy(filename); StripTailDirSlashes(copy); - int result = stat64(copy.c_str(), &file_info); + int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info); return (result == 0); } @@ -95,7 +95,7 @@ bool IsDirectory(const std::string &filename) std::string copy(filename); StripTailDirSlashes(copy); - int result = stat64(copy.c_str(), &file_info); + int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info); if (result < 0) { WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", @@ -344,7 +344,7 @@ u64 GetSize(const std::string &filename) return 0; } struct stat64 buf; - if (stat64(filename.c_str(), &buf) == 0) + if (_tstat64(UTF8ToTStr(filename).c_str(), &buf) == 0) { DEBUG_LOG(COMMON, "GetSize: %s: %lld", filename.c_str(), (long long)buf.st_size); @@ -392,13 +392,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; } @@ -623,14 +623,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; @@ -731,31 +731,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() @@ -799,7 +787,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 diff --git a/Source/Core/Common/Src/SDCardUtil.cpp b/Source/Core/Common/Src/SDCardUtil.cpp index 0f2ad08607..cf37ffff3e 100644 --- a/Source/Core/Common/Src/SDCardUtil.cpp +++ b/Source/Core/Common/Src/SDCardUtil.cpp @@ -29,6 +29,7 @@ // Modified for Dolphin. #include "SDCardUtil.h" +#include "FileUtil.h" #include #include @@ -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; @@ -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); @@ -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; } From 536c110b31339eab5437c5f023494a9ec5c9364b Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 20:04:07 -0600 Subject: [PATCH 05/26] Fix "DiscIO" to build with "Unicode". --- Source/Core/DiscIO/DiscIO.vcxproj | 4 ++-- Source/Core/DiscIO/Src/DriveBlob.cpp | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj index 6dd24ddd44..722aae2040 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj +++ b/Source/Core/DiscIO/DiscIO.vcxproj @@ -44,7 +44,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary @@ -54,7 +54,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary diff --git a/Source/Core/DiscIO/Src/DriveBlob.cpp b/Source/Core/DiscIO/Src/DriveBlob.cpp index e69f8ff34c..2638f3fac4 100644 --- a/Source/Core/DiscIO/Src/DriveBlob.cpp +++ b/Source/Core/DiscIO/Src/DriveBlob.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "DriveBlob.h" +#include "StringUtil.h" namespace DiscIO { @@ -23,12 +24,9 @@ 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) { From 6f87611767ea9072a2680154b26dd8d3f2dd0222 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 20:27:22 -0600 Subject: [PATCH 06/26] Fix "Core" to build with "Unicode". --- Source/Core/Core/Core.vcxproj | 6 +-- Source/Core/Core/Src/ConfigManager.cpp | 6 +-- Source/Core/Core/Src/Console.cpp | 4 +- Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp | 46 +++++++++---------- Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h | 14 +++--- Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp | 6 +-- .../Core/Src/HW/WiimoteReal/WiimoteReal.h | 2 +- .../Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp | 5 +- 8 files changed, 41 insertions(+), 48 deletions(-) diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 1dd547b2ea..17495de740 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -44,7 +44,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary @@ -54,7 +54,7 @@ false StaticLibrary - MultiByte + Unicode StaticLibrary @@ -602,4 +602,4 @@ - + \ No newline at end of file diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index 85ecc7143f..8c7872119e 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -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); } @@ -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]); } @@ -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, ""); diff --git a/Source/Core/Core/Src/Console.cpp b/Source/Core/Core/Src/Console.cpp index 759dc46bc5..b0ef416a84 100644 --- a/Source/Core/Core/Src/Console.cpp +++ b/Source/Core/Core/Src/Console.cpp @@ -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); diff --git a/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp b/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp index 87ebd90344..03332d3012 100644 --- a/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp +++ b/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp @@ -25,7 +25,7 @@ namespace Win32TAPHelper { -bool IsTAPDevice(const char *guid) +bool IsTAPDevice(const TCHAR *guid) { HKEY netcard_key; LONG status; @@ -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); @@ -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); @@ -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); @@ -96,7 +96,7 @@ bool IsTAPDevice(const char *guid) return false; } -bool GetGUIDs(std::vector& guids) +bool GetGUIDs(std::vector>& guids) { LONG status; HKEY control_net_key; @@ -111,12 +111,12 @@ bool GetGUIDs(std::vector& 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, @@ -127,8 +127,8 @@ bool GetGUIDs(std::vector& 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); @@ -165,15 +165,11 @@ bool GetGUIDs(std::vector& guids) return true; } -bool OpenTAP(HANDLE& adapter, const std::string device_guid) +bool OpenTAP(HANDLE& adapter, const std::basic_string& 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) @@ -192,7 +188,7 @@ bool CEXIETHERNET::Activate() return true; DWORD len; - std::vector device_guids; + std::vector> device_guids; if (!Win32TAPHelper::GetGUIDs(device_guids)) { diff --git a/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h b/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h index 2676a3fc7e..2a5bc52ffa 100644 --- a/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h +++ b/Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h @@ -65,18 +65,18 @@ // 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 @@ -84,4 +84,4 @@ // simultaneously. //========================================================= -#define TAP_COMPONENT_ID "tap0901" +#define TAP_COMPONENT_ID _T("tap0901") diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp index 2ae34a7ca5..2407d697a4 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -464,9 +463,6 @@ int Wiimote::IOWrite(const u8* buf, int len) template 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; @@ -509,7 +505,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); } diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index 793a13ceb0..cfc66106b4 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -91,7 +91,7 @@ public: int int_sock; // Interrupt socket #elif defined(_WIN32) - std::string devicepath; // Unique wiimote reference + std::basic_string devicepath; // Unique wiimote reference //ULONGLONG btaddr; // Bluetooth address HANDLE dev_handle; // HID handle OVERLAPPED hid_overlap_read, hid_overlap_write; // Overlap handle diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 3eb0096929..363176e18a 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -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 @@ -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()); @@ -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()); From e82d976d2f2e2f026ecdcdbe978ce7eaeb0da804 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 20:55:19 -0600 Subject: [PATCH 07/26] Buildfix for non-legacy OSes. --- Source/Core/Common/Src/FileUtil.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 78685bbe70..7b9ab2e464 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -82,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); } @@ -95,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", @@ -343,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); From 56f09d3b91479deb0f3ae3c7ce623c7a4724e087 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 27 Feb 2013 22:37:38 -0600 Subject: [PATCH 08/26] Attempt to be consistent with conversions between std::string and wxString. --- Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp | 11 +-- Source/Core/DolphinWX/Src/AboutDolphin.cpp | 3 +- Source/Core/DolphinWX/Src/CheatsWindow.cpp | 13 ++-- Source/Core/DolphinWX/Src/ConfigMain.cpp | 42 +++++------ .../DolphinWX/Src/Debugger/BreakpointDlg.cpp | 5 +- .../DolphinWX/Src/Debugger/BreakpointView.cpp | 19 ++--- .../Core/DolphinWX/Src/Debugger/CodeView.cpp | 39 +++++----- .../DolphinWX/Src/Debugger/CodeWindow.cpp | 21 +++--- .../Src/Debugger/CodeWindowFunctions.cpp | 20 ++--- .../DolphinWX/Src/Debugger/DSPDebugWindow.cpp | 6 +- .../Src/Debugger/DSPRegisterView.cpp | 4 +- .../Core/DolphinWX/Src/Debugger/JitWindow.cpp | 1 + .../DolphinWX/Src/Debugger/MemoryCheckDlg.cpp | 5 +- .../DolphinWX/Src/Debugger/MemoryView.cpp | 26 ++++--- .../DolphinWX/Src/Debugger/MemoryWindow.cpp | 17 ++--- .../DolphinWX/Src/Debugger/RegisterView.cpp | 9 ++- Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp | 7 +- Source/Core/DolphinWX/Src/FrameAui.cpp | 11 +-- Source/Core/DolphinWX/Src/FrameTools.cpp | 27 ++++--- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 34 ++++----- Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp | 9 ++- Source/Core/DolphinWX/Src/ISOFile.cpp | 3 +- Source/Core/DolphinWX/Src/ISOProperties.cpp | 36 ++++----- Source/Core/DolphinWX/Src/InputConfigDiag.cpp | 75 +++++++++---------- .../DolphinWX/Src/InputConfigDiagBitmaps.cpp | 11 +-- Source/Core/DolphinWX/Src/LogConfigWindow.cpp | 3 +- Source/Core/DolphinWX/Src/Main.cpp | 24 +++--- Source/Core/DolphinWX/Src/MemcardManager.cpp | 28 +++---- Source/Core/DolphinWX/Src/NetWindow.cpp | 45 +++++------ Source/Core/DolphinWX/Src/PHackSettings.cpp | 13 ++-- Source/Core/DolphinWX/Src/PatchAddEdit.cpp | 9 ++- Source/Core/DolphinWX/Src/UDPConfigDiag.cpp | 8 +- Source/Core/DolphinWX/Src/VideoConfigDiag.cpp | 18 ++--- Source/Core/DolphinWX/Src/VideoConfigDiag.h | 5 +- Source/Core/DolphinWX/Src/WxUtils.cpp | 16 +++- Source/Core/DolphinWX/Src/WxUtils.h | 9 ++- Source/Core/DolphinWX/Src/X11Utils.cpp | 3 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 3 +- .../Src/VideoConfigDialog.cpp | 6 +- 39 files changed, 344 insertions(+), 300 deletions(-) diff --git a/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp b/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp index c3ed12bbea..e08753f40f 100644 --- a/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp +++ b/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp @@ -17,6 +17,7 @@ #include "ARCodeAddEdit.h" #include "ARDecrypt.h" +#include "WxUtils.h" extern std::vector arCodes; @@ -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); } @@ -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); } @@ -84,7 +85,7 @@ void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event)) // Split the entered cheat into lines. std::vector 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++) { @@ -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; @@ -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; } diff --git a/Source/Core/DolphinWX/Src/AboutDolphin.cpp b/Source/Core/DolphinWX/Src/AboutDolphin.cpp index 5e1825b6ae..eeecf18d48 100644 --- a/Source/Core/DolphinWX/Src/AboutDolphin.cpp +++ b/Source/Core/DolphinWX/Src/AboutDolphin.cpp @@ -17,6 +17,7 @@ #include "Common.h" #include "AboutDolphin.h" +#include "WxUtils.h" #include "../resources/dolphin_logo.cpp" #include "scmrev.h" @@ -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.c_str())); Message->Wrap(GetSize().GetWidth()); wxBoxSizer* const sInfo = new wxBoxSizer(wxVERTICAL); diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.cpp b/Source/Core/DolphinWX/Src/CheatsWindow.cpp index 63ddced86b..1e0f714467 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Src/CheatsWindow.cpp @@ -24,6 +24,7 @@ #include "ISOProperties.h" #include "HW/Memmap.h" #include "Frame.h" +#include "WxUtils.h" #define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256 @@ -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; @@ -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)); } } } @@ -347,7 +348,7 @@ void wxCheatsWindow::OnEvent_ButtonUpdateLog_Press(wxCommandEvent& WXUNUSED (eve const std::vector &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].c_str())); } } @@ -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); diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index dc044afe09..bdb4cdc7fe 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -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" @@ -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. @@ -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])); } } @@ -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() @@ -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; @@ -982,9 +982,9 @@ void CConfigMain::AddAudioBackends() for (std::vector::const_iterator iter = backends.begin(); iter != backends.end(); ++iter) { - BackendSelection->Append(wxString::FromAscii((*iter).c_str())); + BackendSelection->Append(StrToWxStr((*iter).c_str())); int num = BackendSelection->\ - FindString(wxString::FromAscii(SConfig::GetInstance().sBackend.c_str())); + FindString(StrToWxStr(SConfig::GetInstance().sBackend.c_str())); BackendSelection->SetSelection(num); } } @@ -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()) { @@ -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)) @@ -1253,24 +1253,24 @@ 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(wxString(NANDPath)); SConfig::GetInstance().m_SYSCONF->UpdateLocation(); DiscIO::cUIDsys::AccessInstance().UpdateLocation(); DiscIO::CSharedContent::AccessInstance().UpdateLocation(); diff --git a/Source/Core/DolphinWX/Src/Debugger/BreakpointDlg.cpp b/Source/Core/DolphinWX/Src/Debugger/BreakpointDlg.cpp index 58e73b167e..96dbac8ff8 100644 --- a/Source/Core/DolphinWX/Src/Debugger/BreakpointDlg.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/BreakpointDlg.cpp @@ -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) @@ -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(); } diff --git a/Source/Core/DolphinWX/Src/Debugger/BreakpointView.cpp b/Source/Core/DolphinWX/Src/Debugger/BreakpointView.cpp index 496cb8fe5d..a23e9194fd 100644 --- a/Source/Core/DolphinWX/Src/Debugger/BreakpointView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/BreakpointView.cpp @@ -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, @@ -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); @@ -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); diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp index f696aaab64..3b22ca339d 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp @@ -23,6 +23,7 @@ #include "Host.h" #include "CodeView.h" #include "SymbolDB.h" +#include "../WxUtils.h" #include #include @@ -223,7 +224,7 @@ 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; @@ -231,7 +232,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) { char temp[24]; sprintf(temp, "%08x", debugger->readInstruction(selection)); - wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(temp))); + wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp))); } break; @@ -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.c_str()))); } } break; @@ -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.c_str())); 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(); @@ -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); } @@ -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); // ------------ } @@ -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) { @@ -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); } } diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp index 601faeaec6..1cff07c0f4 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp @@ -30,6 +30,7 @@ #include "CodeWindow.h" #include "CodeView.h" +#include "../WxUtils.h" #include "FileUtil.h" #include "Core.h" #include "HW/Memmap.h" @@ -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) { @@ -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); } @@ -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); } @@ -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.c_str())); 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 @@ -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); @@ -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" @@ -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; diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index 706b398dce..a11783c010 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -25,6 +25,7 @@ #include "DebuggerUIUtil.h" +#include "../WxUtils.h" #include "RegisterWindow.h" #include "BreakpointWindow.h" #include "MemoryWindow.h" @@ -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.c_str())); // Boot to pause or not ini.Get("General", "AutomaticStart", &bAutomaticStart, false); @@ -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)); @@ -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" @@ -284,7 +285,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event) if (!path.IsEmpty()) { - std::ifstream f(path.mb_str()); + std::ifstream f(WxStrToStr(path)); std::string line; while (std::getline(f, line)) @@ -312,13 +313,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, @@ -328,8 +329,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()); } } } @@ -343,7 +343,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); } } @@ -366,7 +366,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.c_str())); symbols->SetClientData(idx, (void*)&iter->second); } symbols->Thaw(); diff --git a/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp index a4591d3994..27da055990 100644 --- a/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp @@ -22,6 +22,7 @@ #include +#include "../WxUtils.h" #include "StringUtil.h" #include "DSPDebugWindow.h" #include "DSPRegisterView.h" @@ -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.c_str())); m_SymbolList->SetClientData(idx, (void*)&iter->second); } m_SymbolList->Thaw(); @@ -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; diff --git a/Source/Core/DolphinWX/Src/Debugger/DSPRegisterView.cpp b/Source/Core/DolphinWX/Src/Debugger/DSPRegisterView.cpp index ca275ba66a..b8634e14dc 100644 --- a/Source/Core/DolphinWX/Src/Debugger/DSPRegisterView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/DSPRegisterView.cpp @@ -17,7 +17,7 @@ #include "DSPDebugWindow.h" #include "DSPRegisterView.h" - +#include "../WxUtils.h" wxString CDSPRegTable::GetValue(int row, int col) { @@ -25,7 +25,7 @@ wxString CDSPRegTable::GetValue(int row, int col) { 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; } diff --git a/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp index 69cee04db5..e80d206112 100644 --- a/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp @@ -37,6 +37,7 @@ #include "Core.h" #include "StringUtil.h" #include "LogManager.h" +#include "../WxUtils.h" #include "../Globals.h" diff --git a/Source/Core/DolphinWX/Src/Debugger/MemoryCheckDlg.cpp b/Source/Core/DolphinWX/Src/Debugger/MemoryCheckDlg.cpp index f66e781ca3..41e09a7451 100644 --- a/Source/Core/DolphinWX/Src/Debugger/MemoryCheckDlg.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/MemoryCheckDlg.cpp @@ -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" @@ -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; diff --git a/Source/Core/DolphinWX/Src/Debugger/MemoryView.cpp b/Source/Core/DolphinWX/Src/Debugger/MemoryView.cpp index c6244fb7de..14d1aed8c0 100644 --- a/Source/Core/DolphinWX/Src/Debugger/MemoryView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/MemoryView.cpp @@ -22,6 +22,8 @@ #include "HW/Memmap.h" #include "MemoryView.h" +#include "../WxUtils.h" + #include #include @@ -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 @@ -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); } @@ -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")); } @@ -361,9 +363,9 @@ 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()); @@ -371,7 +373,7 @@ void CMemoryView::OnPaint(wxPaintEvent& event) 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)) diff --git a/Source/Core/DolphinWX/Src/Debugger/MemoryWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/MemoryWindow.cpp index 5673d7b7c1..4b87cfa154 100644 --- a/Source/Core/DolphinWX/Src/Debugger/MemoryWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/MemoryWindow.cpp @@ -20,6 +20,8 @@ #include #include #include + +#include "../WxUtils.h" #include "MemoryWindow.h" #include "HW/CPU.h" #include "PowerPC/PowerPC.h" @@ -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; @@ -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); } @@ -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++) @@ -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]; @@ -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++) diff --git a/Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp b/Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp index c4a30fd522..0c414cb522 100644 --- a/Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp @@ -20,6 +20,7 @@ #include "PowerPC/PowerPC.h" #include "HW/ProcessorInterface.h" #include "IniFile.h" +#include "../WxUtils.h" // F-zero 80005e60 wtf?? @@ -51,9 +52,9 @@ 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; @@ -61,7 +62,7 @@ wxString CRegTable::GetValue(int row, int col) } 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; } @@ -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) diff --git a/Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp b/Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp index 81268e3467..6e18c192eb 100644 --- a/Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp +++ b/Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp @@ -22,6 +22,7 @@ #include "FifoPlayer/FifoPlayer.h" #include "FifoPlayer/FifoRecorder.h" #include "OpcodeDecoding.h" +#include "WxUtils.h" #include #include @@ -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) @@ -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"); } diff --git a/Source/Core/DolphinWX/Src/FrameAui.cpp b/Source/Core/DolphinWX/Src/FrameAui.cpp index 0550c5cd39..fd3cbb662b 100644 --- a/Source/Core/DolphinWX/Src/FrameAui.cpp +++ b/Source/Core/DolphinWX/Src/FrameAui.cpp @@ -21,6 +21,7 @@ #include "Globals.h" // Local #include "Frame.h" #include "LogWindow.h" +#include "WxUtils.h" #include "ConfigManager.h" // Core @@ -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.c_str()), wxT(""), wxITEM_CHECK); menuPopup->Append(mItem); if (i == ActivePerspective) mItem->Check(true); @@ -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: @@ -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(); @@ -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.c_str()); SplitString(_Width, ',', _SWidth); SplitString(_Height, ',', _SHeight); @@ -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++) diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index cb2750ade4..a1dcd959fe 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -101,7 +101,7 @@ void CFrame::CreateMenu() drives = cdio_get_devices(); // Windows Limitation of 24 character drives for (unsigned int i = 0; i < drives.size() && i < 24; i++) { - externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i].c_str())); + externalDrive->Append(IDM_DRIVE1 + i, StrToWxStr(drives[i].c_str())); } fileMenu->AppendSeparator(); @@ -601,12 +601,10 @@ void CFrame::DoOpen(bool Boot) // Should we boot a new game or just change the disc? if (Boot && !path.IsEmpty()) - BootGame(std::string(path.mb_str())); + BootGame(WxStrToStr(path)); else { - char newDiscpath[2048]; - strncpy(newDiscpath, path.mb_str(), strlen(path.mb_str())+1); - DVDInterface::ChangeDisc(newDiscpath); + DVDInterface::ChangeDisc(WxStrToStr(path).c_str()); } } @@ -693,7 +691,7 @@ void CFrame::OnPlayRecording(wxCommandEvent& WXUNUSED (event)) GetMenuBar()->FindItem(IDM_RECORDREADONLY)->Check(true); } - if(Movie::PlayInput(path.mb_str())) + if (Movie::PlayInput(WxStrToStr(path).c_str())) BootGame(std::string("")); } @@ -1015,7 +1013,7 @@ void CFrame::DoStop() X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()), X11Utils::XWindowFromHandle(GetHandle()), false); #endif - m_RenderFrame->SetTitle(wxString::FromAscii(scm_rev_str)); + m_RenderFrame->SetTitle(StrToWxStr(scm_rev_str)); // Destroy the renderer frame when not rendering to main m_RenderParent->Unbind(wxEVT_SIZE, &CFrame::OnRenderParentResize, this); @@ -1081,7 +1079,7 @@ void CFrame::DoRecordingSave() if(path.IsEmpty()) return; - Movie::SaveRecording(path.mb_str()); + Movie::SaveRecording(WxStrToStr(path).c_str()); if (!paused) DoPause(); @@ -1212,7 +1210,7 @@ void CFrame::StatusBarMessage(const char * Text, ...) vsnprintf(Str, MAX_BYTES, Text, ArgPtr); va_end(ArgPtr); - if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxString::FromAscii(Str),0); + if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(StrToWxStr(Str),0); } @@ -1248,7 +1246,8 @@ void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event)) if (!path.IsEmpty()) { - CWiiSaveCrypted* saveFile = new CWiiSaveCrypted(path.mb_str()); + // TODO: Does this actually need to be dynamically allocated for some reason? + CWiiSaveCrypted* saveFile = new CWiiSaveCrypted(WxStrToStr(path).c_str()); delete saveFile; } } @@ -1288,7 +1287,7 @@ void CFrame::OnInstallWAD(wxCommandEvent& event) _T("Wii WAD file (*.wad)|*.wad"), wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST, this); - fileName = path.mb_str(); + fileName = WxStrToStr(path); break; } default: @@ -1354,7 +1353,7 @@ void CFrame::ConnectWiimote(int wm_idx, bool connect) GetUsbPointer()->AccessWiiMote(wm_idx | 0x100)->Activate(connect); wxString msg(wxString::Format(wxT("Wiimote %i %s"), wm_idx + 1, connect ? wxT("Connected") : wxT("Disconnected"))); - Core::DisplayMessage(msg.ToAscii(), 3000); + Core::DisplayMessage(WxStrToStr(msg), 3000); Host_UpdateMainFrame(); } } @@ -1394,7 +1393,7 @@ void CFrame::OnLoadStateFromFile(wxCommandEvent& WXUNUSED (event)) this); if (!path.IsEmpty()) - State::LoadAs((const char*)path.mb_str()); + State::LoadAs(WxStrToStr(path)); } void CFrame::OnSaveStateToFile(wxCommandEvent& WXUNUSED (event)) @@ -1408,7 +1407,7 @@ void CFrame::OnSaveStateToFile(wxCommandEvent& WXUNUSED (event)) this); if (!path.IsEmpty()) - State::SaveAs((const char*)path.mb_str()); + State::SaveAs(WxStrToStr(path)); } void CFrame::OnLoadLastState(wxCommandEvent& WXUNUSED (event)) diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 6fd298ad81..d385b947e5 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -257,7 +257,7 @@ void CGameListCtrl::BrowseForDirectory() if (dialog.ShowModal() == wxID_OK) { - std::string sPath(dialog.GetPath().mb_str()); + std::string sPath(WxStrToStr(dialog.GetPath())); std::vector::iterator itResult = std::find( SConfig::GetInstance().m_ISOFolder.begin(), SConfig::GetInstance().m_ISOFolder.end(), sPath); @@ -402,7 +402,7 @@ wxString NiceSizeFormat(s64 _size) wxString NiceString; char tempstr[32]; sprintf(tempstr,"%3.1f %s", f, sizes[s]); - NiceString = wxString::FromAscii(tempstr); + NiceString = StrToWxStr(tempstr); return(NiceString); } @@ -614,7 +614,7 @@ void CGameListCtrl::ScanForISOs() // Update with the progress (i) and the message dialog.Update(i, wxString::Format(_("Scanning %s"), - wxString(FileName.c_str(), *wxConvCurrent).c_str())); + StrToWxStr(FileName).c_str())); if (dialog.WasCancelled()) break; @@ -858,7 +858,7 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event) char temp[2048]; sprintf(temp, "^ %s%s%s", emuState[emu_state - 1], issues.size() > 0 ? " :\n" : "", issues.c_str()); - toolTip = new wxEmuStateTip(this, wxString(temp, *wxConvCurrent), &toolTip); + toolTip = new wxEmuStateTip(this, StrToWxStr(temp), &toolTip); } else toolTip = new wxEmuStateTip(this, _("Not Set"), &toolTip); @@ -1115,9 +1115,9 @@ void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED (event)) void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg) { percent = (((float)m_currentItem) + percent) / (float)m_numberItem; - wxString textString(StringFromFormat("%s (%i/%i) - %s", + wxString textString(StrToWxStr(StringFromFormat("%s (%i/%i) - %s", m_currentFilename.c_str(), (int)m_currentItem+1, - (int)m_numberItem, text).c_str(), *wxConvCurrent); + (int)m_numberItem, text))); ((wxProgressDialog*)arg)->Update((int)(percent*1000), textString); } @@ -1170,13 +1170,13 @@ void CGameListCtrl::CompressSelection(bool _compress) std::string OutputFileName; BuildCompleteFilename(OutputFileName, - (const char *)browseDialog.GetPath().mb_str(wxConvUTF8), + WxStrToStr(browseDialog.GetPath()), FileName); - if (wxFileExists(wxString::FromAscii(OutputFileName.c_str())) && + if (wxFileExists(StrToWxStr(OutputFileName.c_str())) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), - wxString(OutputFileName.c_str(), *wxConvCurrent).c_str()), + StrToWxStr(OutputFileName).c_str()), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; @@ -1198,13 +1198,13 @@ void CGameListCtrl::CompressSelection(bool _compress) std::string OutputFileName; BuildCompleteFilename(OutputFileName, - (const char *)browseDialog.GetPath().mb_str(wxConvUTF8), + WxStrToStr(browseDialog.GetPath()), FileName); - if (wxFileExists(wxString::FromAscii(OutputFileName.c_str())) && + if (wxFileExists(StrToWxStr(OutputFileName.c_str())) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), - wxString(OutputFileName.c_str(), *wxConvCurrent).c_str()), + StrToWxStr(OutputFileName).c_str()), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; @@ -1225,7 +1225,7 @@ void CGameListCtrl::CompressSelection(bool _compress) void CGameListCtrl::CompressCB(const char* text, float percent, void* arg) { ((wxProgressDialog*)arg)-> - Update((int)(percent*1000), wxString(text, *wxConvCurrent)); + Update((int)(percent*1000), StrToWxStr(text)); } void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event)) @@ -1251,8 +1251,8 @@ void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event)) path = wxFileSelector( _("Save decompressed GCM/ISO"), - wxString(FilePath.c_str(), *wxConvCurrent), - wxString(FileName.c_str(), *wxConvCurrent) + FileType.After('*'), + StrToWxStr(FilePath), + StrToWxStr(FileName) + FileType.After('*'), wxEmptyString, FileType + wxT("|") + wxGetTranslation(wxALL_FILES), wxFD_SAVE, @@ -1262,8 +1262,8 @@ void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event)) { path = wxFileSelector( _("Save compressed GCM/ISO"), - wxString(FilePath.c_str(), *wxConvCurrent), - wxString(FileName.c_str(), *wxConvCurrent) + _T(".gcz"), + StrToWxStr(FilePath), + StrToWxStr(FileName) + _T(".gcz"), wxEmptyString, _("All compressed GC/Wii ISO files (gcz)") + wxString::Format(wxT("|*.gcz|%s"), wxGetTranslation(wxALL_FILES)), diff --git a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp index e015c55ae8..76d4833c0b 100644 --- a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp +++ b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp @@ -13,6 +13,7 @@ // If not, see http://www.gnu.org/licenses/ #include "GeckoCodeDiag.h" +#include "WxUtils.h" #include @@ -76,7 +77,7 @@ void CodeConfigPanel::UpdateCodeList() gcodes_end = m_gcodes.end(); for (; gcodes_iter!=gcodes_end; ++gcodes_iter) { - m_listbox_gcodes->Append(wxString(gcodes_iter->name.c_str(), *wxConvCurrent)); + m_listbox_gcodes->Append(StrToWxStr(gcodes_iter->name)); if (gcodes_iter->enabled) m_listbox_gcodes->Check(m_listbox_gcodes->GetCount()-1, true); } @@ -109,7 +110,7 @@ void CodeConfigPanel::UpdateInfoBox(wxCommandEvent&) if (sel > -1) { - m_infobox.label_name->SetLabel(wxGetTranslation(wxstr_name) + wxString(m_gcodes[sel].name.c_str(), *wxConvCurrent)); + m_infobox.label_name->SetLabel(wxGetTranslation(wxstr_name) + StrToWxStr(m_gcodes[sel].name)); // notes textctrl m_infobox.textctrl_notes->Clear(); @@ -117,10 +118,10 @@ void CodeConfigPanel::UpdateInfoBox(wxCommandEvent&) notes_iter = m_gcodes[sel].notes.begin(), notes_end = m_gcodes[sel].notes.end(); for (; notes_iter!=notes_end; ++notes_iter) - m_infobox.textctrl_notes->AppendText(wxString(notes_iter->c_str(), *wxConvCurrent)); + m_infobox.textctrl_notes->AppendText(StrToWxStr(*notes_iter)); m_infobox.textctrl_notes->ScrollLines(-99); // silly - m_infobox.label_creator->SetLabel(wxGetTranslation(wxstr_creator) + wxString(m_gcodes[sel].creator.c_str(), *wxConvCurrent)); + m_infobox.label_creator->SetLabel(wxGetTranslation(wxstr_creator) + StrToWxStr(m_gcodes[sel].creator)); // add codes to info listbox std::vector::const_iterator diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index 833268ad63..639190fa0e 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -28,6 +28,7 @@ #include "StringUtil.h" #include "Hash.h" #include "IniFile.h" +#include "WxUtils.h" #include "Filesystem.h" #include "BannerLoader.h" @@ -331,7 +332,7 @@ const std::string GameListItem::GetWiiFSPath() const File::CreateFullPath(Path); if (Path[0] == '.') - ret = std::string(wxGetCwd().mb_str()) + std::string(Path).substr(strlen(ROOT_DIR)); + ret = WxStrToStr(wxGetCwd()) + std::string(Path).substr(strlen(ROOT_DIR)); else ret = std::string(Path); } diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index c44aad5d5b..e739ff043b 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -23,6 +23,7 @@ #include "CommonPaths.h" #include "Globals.h" +#include "WxUtils.h" #include "VolumeCreator.h" #include "Filesystem.h" #include "ISOProperties.h" @@ -663,10 +664,10 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event)) { int partitionNum = wxAtoi(File.SubString(10, 11)); File.Remove(0, 12); // Remove "Partition x/" - WiiDisc.at(partitionNum).FileSystem->ExportFile(File.mb_str(), Path.mb_str()); + WiiDisc.at(partitionNum).FileSystem->ExportFile(WxStrToStr(File).c_str(), WxStrToStr(Path).c_str()); } else - pFileSystem->ExportFile(File.mb_str(), Path.mb_str()); + pFileSystem->ExportFile(WxStrToStr(File).c_str(), WxStrToStr(Path).c_str()); } void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolder, const int partitionNum) @@ -727,7 +728,7 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde (u32)(((float)(i - index[0]) / (float)(index[1] - index[0])) * 100))); dialog.Update(i, wxString::Format(_("Extracting %s"), - wxString(fst[i]->m_FullPath, *wxConvCurrent).c_str())); + StrToWxStr(fst[i]->m_FullPath).c_str())); if (dialog.WasCancelled()) break; @@ -778,9 +779,9 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event) { if (DiscIO::IsVolumeWiiDisc(OpenISO)) for (u32 i = 0; i < WiiDisc.size(); i++) - ExportDir(NULL, Path.mb_str(), i); + ExportDir(NULL, WxStrToStr(Path).c_str(), i); else - ExportDir(NULL, Path.mb_str()); + ExportDir(NULL, WxStrToStr(Path).c_str()); return; } @@ -798,10 +799,10 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event) { int partitionNum = wxAtoi(Directory.SubString(10, 11)); Directory.Remove(0, 12); // Remove "Partition x/" - ExportDir(Directory.mb_str(), Path.mb_str(), partitionNum); + ExportDir(WxStrToStr(Directory).c_str(), WxStrToStr(Path).c_str(), partitionNum); } else - ExportDir(Directory.mb_str(), Path.mb_str()); + ExportDir(WxStrToStr(Directory).c_str(), WxStrToStr(Path).c_str()); } void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event) @@ -821,15 +822,15 @@ void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event) bool ret = false; if (event.GetId() == IDM_EXTRACTAPPLOADER) { - ret = FS->ExportApploader(Path.mb_str()); + ret = FS->ExportApploader(WxStrToStr(Path).c_str()); } else if (event.GetId() == IDM_EXTRACTDOL) { - ret = FS->ExportDOL(Path.mb_str()); + ret = FS->ExportDOL(WxStrToStr(Path).c_str()); } if (!ret) - PanicAlertT("Failed to extract to %s!", (const char *)Path.mb_str()); + PanicAlertT("Failed to extract to %s!", WxStrToStr(Path).c_str()); } class IntegrityCheckThread : public wxThread @@ -989,7 +990,7 @@ void CISOProperties::LoadGameConfig() GameIni.Get("EmuState", "EmulationIssues", &sTemp); if (!sTemp.empty()) { - EmuIssues->SetValue(wxString(sTemp.c_str(), *wxConvCurrent)); + EmuIssues->SetValue(StrToWxStr(sTemp.c_str())); } EmuIssues->Enable(EmuState->GetSelection() != 0); @@ -1075,7 +1076,7 @@ bool CISOProperties::SaveGameConfig() GameIni.Get("EmuState","EmulationIssues", &sTemp); if (EmuIssues->GetValue() != sTemp) bRefreshList = true; - GameIni.Set("EmuState", "EmulationIssues", (const char*)EmuIssues->GetValue().mb_str(*wxConvCurrent)); + GameIni.Set("EmuState", "EmulationIssues", WxStrToStr(EmuIssues->GetValue())); PatchList_Save(); ActionReplayList_Save(); @@ -1156,7 +1157,7 @@ void CISOProperties::PatchList_Load() for (std::vector::const_iterator it = onFrame.begin(); it != onFrame.end(); ++it) { PatchEngine::Patch p = *it; - Patches->Append(wxString(p.name.c_str(), *wxConvCurrent)); + Patches->Append(StrToWxStr(p.name.c_str())); Patches->Check(index, p.active); ++index; } @@ -1209,7 +1210,7 @@ void CISOProperties::PatchButtonClicked(wxCommandEvent& event) CPatchAddEdit dlg(-1, this, 1, _("Add Patch")); if (dlg.ShowModal() == wxID_OK) { - Patches->Append(wxString(onFrame.back().name.c_str(), *wxConvCurrent)); + Patches->Append(StrToWxStr(onFrame.back().name)); Patches->Check((unsigned int)(onFrame.size() - 1), onFrame.back().active); } } @@ -1238,7 +1239,7 @@ void CISOProperties::ActionReplayList_Load() for (std::vector::const_iterator it = arCodes.begin(); it != arCodes.end(); ++it) { ActionReplay::ARCode arCode = *it; - Cheats->Append(wxString(arCode.name.c_str(), *wxConvCurrent)); + Cheats->Append(StrToWxStr(arCode.name)); Cheats->Check(index, arCode.active); ++index; } @@ -1256,7 +1257,7 @@ void CISOProperties::ActionReplayList_Save() for (std::vector::const_iterator iter2 = code.ops.begin(); iter2 != code.ops.end(); ++iter2) { - lines.push_back(std::string(wxString::Format(wxT("%08X %08X"), iter2->cmd_addr, iter2->value).mb_str())); + lines.push_back(WxStrToStr(wxString::Format(wxT("%08X %08X"), iter2->cmd_addr, iter2->value))); } ++index; } @@ -1364,5 +1365,6 @@ void CISOProperties::ChangeBannerDetails(int lang) std::string filename, extension; SplitPath(OpenGameListItem->GetFileName(), 0, &filename, &extension); // Also sets the window's title - SetTitle(wxString(StringFromFormat("%s%s: %s - ", filename.c_str(), extension.c_str(), OpenGameListItem->GetUniqueID().c_str()).c_str(), *wxConvCurrent)+shortName); + SetTitle(StrToWxStr(StringFromFormat("%s%s: %s - ", filename.c_str(), + extension.c_str(), OpenGameListItem->GetUniqueID().c_str()).c_str()) + shortName); } diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp index 1efcf98af6..d8a755aca6 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp @@ -17,10 +17,7 @@ #include "InputConfigDiag.h" #include "UDPConfigDiag.h" - -#define WXSTR_FROM_STR(s) (wxString::FromUTF8((s).c_str())) -#define WXTSTR_FROM_CSTR(s) (wxGetTranslation(wxString::FromUTF8(s))) -#define STR_FROM_WXSTR(w) (std::string((w).ToUTF8())) +#include "WxUtils.h" void GamepadPage::ConfigUDPWii(wxCommandEvent &event) { @@ -37,7 +34,7 @@ void GamepadPage::ConfigExtension(wxCommandEvent& event) if (ex->switch_extension) { wxDialog dlg(this, -1, - WXTSTR_FROM_CSTR(ex->attachments[ex->switch_extension]->GetName().c_str()), + StrToWxStr(ex->attachments[ex->switch_extension]->GetName().c_str()), wxDefaultPosition, wxDefaultSize); wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL); @@ -67,7 +64,7 @@ PadSettingExtension::PadSettingExtension(wxWindow* const parent, ControllerEmu:: e = extension->attachments.end(); for (; i!=e; ++i) - ((wxChoice*)wxcontrol)->Append(WXTSTR_FROM_CSTR((*i)->GetName().c_str())); + ((wxChoice*)wxcontrol)->Append(StrToWxStr((*i)->GetName().c_str())); UpdateGUI(); } @@ -83,7 +80,7 @@ void PadSettingExtension::UpdateValue() } PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent, ControlState& _value, const char* const label) - : PadSetting(new wxCheckBox(parent, -1, WXTSTR_FROM_CSTR(label), wxDefaultPosition)) + : PadSetting(new wxCheckBox(parent, -1, StrToWxStr(label), wxDefaultPosition)) , value(_value) { UpdateGUI(); @@ -119,8 +116,8 @@ ControlDialog::ControlDialog(GamepadPage* const parent, InputPlugin& plugin, Con m_devq = m_parent->controller->default_device; // GetStrings() sounds slow :/ - //device_cbox = new wxComboBox(this, -1, WXSTR_FROM_STR(ref->device_qualifier.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER); - device_cbox = new wxComboBox(this, -1, WXSTR_FROM_STR(m_devq.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER); + //device_cbox = new wxComboBox(this, -1, StrToWxStr(ref->device_qualifier.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER); + device_cbox = new wxComboBox(this, -1, StrToWxStr(m_devq.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER); device_cbox->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &ControlDialog::SetDevice, this); device_cbox->Bind(wxEVT_COMMAND_TEXT_ENTER, &ControlDialog::SetDevice, this); @@ -145,9 +142,9 @@ ControlButton::ControlButton(wxWindow* const parent, ControllerInterface::Contro , control_reference(_ref) { if (label.empty()) - SetLabel(WXSTR_FROM_STR(_ref->expression)); + SetLabel(StrToWxStr(_ref->expression)); else - SetLabel(WXSTR_FROM_STR(label)); + SetLabel(StrToWxStr(label)); } void InputConfigDialog::UpdateProfileComboBox() @@ -169,7 +166,7 @@ void InputConfigDialog::UpdateProfileComboBox() for (; si!=se; ++si) { std::string str(si->begin() + si->find_last_of('/') + 1 , si->end() - 4) ; - strs.push_back(WXSTR_FROM_STR(str)); + strs.push_back(StrToWxStr(str)); } std::vector< GamepadPage* >::iterator i = m_padpages.begin(), @@ -209,7 +206,7 @@ void ControlDialog::UpdateListContents() i = dev->Inputs().begin(), e = dev->Inputs().end(); for (; i!=e; ++i) - control_lbox->Append(WXSTR_FROM_STR((*i)->GetName())); + control_lbox->Append(StrToWxStr((*i)->GetName())); } else { @@ -218,7 +215,7 @@ void ControlDialog::UpdateListContents() i = dev->Outputs().begin(), e = dev->Outputs().end(); for (; i!=e; ++i) - control_lbox->Append(WXSTR_FROM_STR((*i)->GetName())); + control_lbox->Append(StrToWxStr((*i)->GetName())); } } } @@ -227,7 +224,7 @@ void ControlDialog::SelectControl(const std::string& name) { //UpdateGUI(); - const int f = control_lbox->FindString(WXSTR_FROM_STR(name)); + const int f = control_lbox->FindString(StrToWxStr(name)); if (f >= 0) control_lbox->Select(f); } @@ -235,7 +232,7 @@ void ControlDialog::SelectControl(const std::string& name) void ControlDialog::UpdateGUI() { // update textbox - textctrl->SetValue(WXSTR_FROM_STR(control_reference->expression)); + textctrl->SetValue(StrToWxStr(control_reference->expression)); // updates the "bound controls:" label m_bound_label->SetLabel(wxString::Format(_("Bound Controls: %lu"), @@ -244,7 +241,7 @@ void ControlDialog::UpdateGUI() void GamepadPage::UpdateGUI() { - device_cbox->SetValue(WXSTR_FROM_STR(controller->default_device.ToString())); + device_cbox->SetValue(StrToWxStr(controller->default_device.ToString())); std::vector< ControlGroupBox* >::const_iterator g = control_groups.begin(), ge = control_groups.end(); @@ -255,7 +252,7 @@ void GamepadPage::UpdateGUI() , e = (*g)->control_buttons.end(); for (; i!=e; ++i) //if (std::string::npos == (*i)->control_reference->expression.find_first_of("`|&!#")) - (*i)->SetLabel(WXSTR_FROM_STR((*i)->control_reference->expression)); + (*i)->SetLabel(StrToWxStr((*i)->control_reference->expression)); //else //(*i)->SetLabel(wxT("...")); @@ -294,7 +291,7 @@ void GamepadPage::LoadDefaults(wxCommandEvent&) void ControlDialog::SetControl(wxCommandEvent&) { - control_reference->expression = STR_FROM_WXSTR(textctrl->GetValue()); + control_reference->expression = WxStrToStr(textctrl->GetValue()); std::lock_guard lk(m_plugin.controls_lock); g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device); @@ -304,10 +301,10 @@ void ControlDialog::SetControl(wxCommandEvent&) void GamepadPage::SetDevice(wxCommandEvent&) { - controller->default_device.FromString(STR_FROM_WXSTR(device_cbox->GetValue())); + controller->default_device.FromString(WxStrToStr(device_cbox->GetValue())); // show user what it was validated as - device_cbox->SetValue(WXSTR_FROM_STR(controller->default_device.ToString())); + device_cbox->SetValue(StrToWxStr(controller->default_device.ToString())); // this will set all the controls to this default device controller->UpdateDefaultDevice(); @@ -319,10 +316,10 @@ void GamepadPage::SetDevice(wxCommandEvent&) void ControlDialog::SetDevice(wxCommandEvent&) { - m_devq.FromString(STR_FROM_WXSTR(device_cbox->GetValue())); + m_devq.FromString(WxStrToStr(device_cbox->GetValue())); // show user what it was validated as - device_cbox->SetValue(WXSTR_FROM_STR(m_devq.ToString())); + device_cbox->SetValue(StrToWxStr(m_devq.ToString())); // update gui UpdateListContents(); @@ -349,12 +346,12 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&) // non-default device if (false == (m_devq == m_parent->controller->default_device)) - expr.append(wxT('`')).append(WXSTR_FROM_STR(m_devq.ToString())).append(wxT('`')); + expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`')); // append the control name expr += control_lbox->GetString(num); - control_reference->expression = STR_FROM_WXSTR(expr); + control_reference->expression = WxStrToStr(expr); std::lock_guard lk(m_plugin.controls_lock); g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device); @@ -380,12 +377,12 @@ void ControlDialog::AppendControl(wxCommandEvent& event) // non-default device if (false == (m_devq == m_parent->controller->default_device)) - expr.append(wxT('`')).append(WXSTR_FROM_STR(m_devq.ToString())).append(wxT('`')); + expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`')); // append the control name expr += control_lbox->GetString(num); - control_reference->expression = STR_FROM_WXSTR(expr); + control_reference->expression = WxStrToStr(expr); std::lock_guard lk(m_plugin.controls_lock); g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device); @@ -475,7 +472,7 @@ void GamepadPage::DetectControl(wxCommandEvent& event) g_controller_interface.UpdateReference(btn->control_reference, controller->default_device); } - btn->SetLabel(WXSTR_FROM_STR(btn->control_reference->expression)); + btn->SetLabel(StrToWxStr(btn->control_reference->expression)); } } @@ -565,7 +562,7 @@ void GamepadPage::GetProfilePath(std::string& path) path += PROFILES_PATH; path += m_plugin.profile_name; path += '/'; - path += STR_FROM_WXSTR(profile_cbox->GetValue()); + path += WxStrToStr(profile_cbox->GetValue()); path += ".ini"; } } @@ -615,7 +612,7 @@ void GamepadPage::DeleteProfile(wxCommandEvent&) if (File::Exists(fnamecstr) && AskYesNoT("Are you sure you want to delete \"%s\"?", - STR_FROM_WXSTR(profile_cbox->GetValue()).c_str())) + WxStrToStr(profile_cbox->GetValue()).c_str())) { File::Delete(fnamecstr); @@ -637,9 +634,9 @@ void InputConfigDialog::UpdateDeviceComboBox() for (; di!=de; ++di) { dq.FromDevice(*di); - (*i)->device_cbox->Append(WXSTR_FROM_STR(dq.ToString())); + (*i)->device_cbox->Append(StrToWxStr(dq.ToString())); } - (*i)->device_cbox->SetValue(WXSTR_FROM_STR((*i)->controller->default_device.ToString())); + (*i)->device_cbox->SetValue(StrToWxStr((*i)->controller->default_device.ToString())); } } @@ -680,7 +677,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin for (; ci != ce; ++ci) { - wxStaticText* const label = new wxStaticText(parent, -1, WXTSTR_FROM_CSTR((*ci)->name)); + wxStaticText* const label = new wxStaticText(parent, -1, StrToWxStr((*ci)->name)); ControlButton* const control_button = new ControlButton(parent, (*ci)->control_ref, 80); control_button->SetFont(m_SmallFont); @@ -734,7 +731,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin PadSettingSpin* setting = new PadSettingSpin(parent, *i); setting->wxcontrol->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &GamepadPage::AdjustSetting, eventsink); options.push_back(setting); - szr->Add(new wxStaticText(parent, -1, WXTSTR_FROM_CSTR((*i)->name))); + szr->Add(new wxStaticText(parent, -1, StrToWxStr((*i)->name))); szr->Add(setting->wxcontrol, 0, wxLEFT, 0); } @@ -760,7 +757,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin options.push_back(threshold_cbox); wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL); - szr->Add(new wxStaticText(parent, -1, WXTSTR_FROM_CSTR(group->settings[0]->name)), + szr->Add(new wxStaticText(parent, -1, StrToWxStr(group->settings[0]->name)), 0, wxCENTER|wxRIGHT, 3); szr->Add(threshold_cbox->wxcontrol, 0, wxRIGHT, 3); @@ -795,7 +792,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin setting->wxcontrol->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &GamepadPage::AdjustSetting, eventsink); options.push_back(setting); wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL); - szr->Add(new wxStaticText(parent, -1, WXTSTR_FROM_CSTR((*i)->name)), 0, wxCENTER|wxRIGHT, 3); + szr->Add(new wxStaticText(parent, -1, StrToWxStr((*i)->name)), 0, wxCENTER|wxRIGHT, 3); szr->Add(setting->wxcontrol, 0, wxRIGHT, 3); Add(szr, 0, wxALL|wxCENTER, 3); } @@ -859,7 +856,7 @@ ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow { ControlGroupBox* control_group_box = new ControlGroupBox(controller->groups[i], parent, eventsink); wxStaticBoxSizer *control_group = - new wxStaticBoxSizer(wxVERTICAL, parent, WXTSTR_FROM_CSTR(controller->groups[i]->name)); + new wxStaticBoxSizer(wxVERTICAL, parent, StrToWxStr(controller->groups[i]->name)); control_group->Add(control_group_box); const size_t grp_size = controller->groups[i]->controls.size() + controller->groups[i]->settings.size(); @@ -955,7 +952,7 @@ GamepadPage::GamepadPage(wxWindow* parent, InputPlugin& plugin, const unsigned i InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputPlugin& plugin, const std::string& name, const int tab_num) - : wxDialog(parent, wxID_ANY, WXTSTR_FROM_CSTR(name.c_str()), wxPoint(128,-1), wxDefaultSize) + : wxDialog(parent, wxID_ANY, StrToWxStr(name.c_str()), wxPoint(128,-1), wxDefaultSize) , m_plugin(plugin) { m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT); @@ -963,7 +960,7 @@ InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputPlugin& plugin { GamepadPage* gp = new GamepadPage(m_pad_notebook, m_plugin, i, this); m_padpages.push_back(gp); - m_pad_notebook->AddPage(gp, wxString::Format(wxT("%s %u"), WXTSTR_FROM_CSTR(m_plugin.gui_name), 1+i)); + m_pad_notebook->AddPage(gp, wxString::Format(wxT("%s %u"), StrToWxStr(m_plugin.gui_name), 1+i)); } m_pad_notebook->SetSelection(tab_num); diff --git a/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp b/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp index ff5ed3b9cd..4e07ed990d 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "InputConfigDiag.h" +#include "WxUtils.h" void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) { @@ -48,7 +49,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) // label for sticks and stuff if (64 == bitmap.GetHeight()) - dc.DrawText(wxString::FromAscii((*g)->control_group->name).Upper(), 4, 2); + dc.DrawText(StrToWxStr((*g)->control_group->name).Upper(), 4, 2); switch ( (*g)->control_group->type ) { @@ -227,7 +228,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) // text const char* const name = (*g)->control_group->controls[n]->name; // bit of hax so ZL, ZR show up as L, R - dc.DrawText(wxString::FromAscii((name[1] && name[1] < 'a') ? name[1] : name[0]), n*12 + 2, 1); + dc.DrawText(StrToWxStr((name[1] && name[1] < 'a') ? name[1] : name[0]), n*12 + 2, 1); } delete[] bitmasks; @@ -263,7 +264,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) dc.DrawRectangle(0, n*12, trigs[n], 14); // text - dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n]->name), 3, n*12 + 1); + dc.DrawText(StrToWxStr((*g)->control_group->controls[n]->name), 3, n*12 + 1); } delete[] trigs; @@ -298,8 +299,8 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) dc.DrawRectangle(64, n*12, 32, 14); // text - dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n+trigger_count]->name), 3, n*12 + 1); - dc.DrawText(wxString::FromAscii((*g)->control_group->controls[n]->name[0]), 64 + 3, n*12 + 1); + dc.DrawText(StrToWxStr((*g)->control_group->controls[n+trigger_count]->name), 3, n*12 + 1); + dc.DrawText(StrToWxStr((*g)->control_group->controls[n]->name[0]), 64 + 3, n*12 + 1); } // threshold box diff --git a/Source/Core/DolphinWX/Src/LogConfigWindow.cpp b/Source/Core/DolphinWX/Src/LogConfigWindow.cpp index 162647c64d..a4a5fa647a 100644 --- a/Source/Core/DolphinWX/Src/LogConfigWindow.cpp +++ b/Source/Core/DolphinWX/Src/LogConfigWindow.cpp @@ -20,6 +20,7 @@ #include "ConsoleListener.h" #include "LogWindow.h" #include "FileUtil.h" +#include "WxUtils.h" LogConfigWindow::LogConfigWindow(wxWindow* parent, CLogWindow *log_window, wxWindowID id) : wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("Log Configuration")) @@ -74,7 +75,7 @@ void LogConfigWindow::CreateGUIControls() m_checks = new wxCheckListBox(this, wxID_ANY); m_checks->Bind(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, &LogConfigWindow::OnLogCheck, this); for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) - m_checks->Append(wxString::FromAscii(m_LogManager->GetFullName((LogTypes::LOG_TYPE)i))); + m_checks->Append(StrToWxStr(m_LogManager->GetFullName((LogTypes::LOG_TYPE)i))); // Sizers wxStaticBoxSizer* sbOutputs = new wxStaticBoxSizer(wxVERTICAL, this, _("Logger Outputs")); diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index d9d1908de3..60a8157c28 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -32,6 +32,7 @@ #include "Host.h" // Core #include "HW/Wiimote.h" +#include "WxUtils.h" #include "Globals.h" // Local #include "Main.h" #include "ConfigManager.h" @@ -211,7 +212,7 @@ bool DolphinApp::OnInit() } #ifdef _WIN32 - if (!wxSetWorkingDirectory(wxString(File::GetExeDirectory().c_str(), *wxConvCurrent))) + if (!wxSetWorkingDirectory(StrToWxStr(File::GetExeDirectory()))) { INFO_LOG(CONSOLE, "set working directory failed"); } @@ -246,7 +247,7 @@ bool DolphinApp::OnInit() if (selectVideoBackend && videoBackendName != wxEmptyString) SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend = - std::string(videoBackendName.mb_str()); + WxStrToStr(videoBackendName); if (selectAudioEmulation) { @@ -296,7 +297,7 @@ bool DolphinApp::OnInit() #endif main_frame = new CFrame((wxFrame*)NULL, wxID_ANY, - wxString::FromAscii(scm_rev_str), + StrToWxStr(scm_rev_str), wxPoint(x, y), wxSize(w, h), UseDebugger, BatchMode, UseLogger); SetTopWindow(main_frame); @@ -317,7 +318,7 @@ void DolphinApp::MacOpenFile(const wxString &fileName) LoadFile = true; if (m_afterinit == NULL) - main_frame->BootGame(std::string(FileToLoad.mb_str())); + main_frame->BootGame(WxStrToStr(FileToLoad)); } void DolphinApp::AfterInit(wxTimerEvent& WXUNUSED(event)) @@ -331,7 +332,7 @@ void DolphinApp::AfterInit(wxTimerEvent& WXUNUSED(event)) // First check if we have an exec command line. if (LoadFile && FileToLoad != wxEmptyString) { - main_frame->BootGame(std::string(FileToLoad.mb_str())); + main_frame->BootGame(WxStrToStr(FileToLoad)); } // If we have selected Automatic Start, start the default ISO, // or if no default ISO exists, start the last loaded ISO @@ -418,7 +419,7 @@ void Host_SysMessage(const char *fmt, ...) va_end(list); if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; - //wxMessageBox(wxString::FromAscii(msg)); + //wxMessageBox(StrToWxStr(msg)); PanicAlert("%s", msg); } @@ -427,14 +428,13 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style* #ifdef __WXGTK__ if (wxIsMainThread()) #endif - return wxYES == wxMessageBox(wxString::FromUTF8(text), - wxString::FromUTF8(caption), + return wxYES == wxMessageBox(StrToWxStr(text), StrToWxStr(caption), (yes_no) ? wxYES_NO : wxOK, wxGetActiveWindow()); #ifdef __WXGTK__ else { wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_PANIC); - event.SetString(wxString::FromUTF8(caption) + wxT(":") + wxString::FromUTF8(text)); + event.SetString(StrToWxStr(caption) + wxT(":") + StrToWxStr(text)); event.SetInt(yes_no); main_frame->GetEventHandler()->AddPendingEvent(event); main_frame->panic_event.Wait(); @@ -445,7 +445,7 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style* std::string wxStringTranslator(const char *text) { - return (const char *)wxString(wxGetTranslation(wxString::From8BitData(text))).ToUTF8(); + return WxStrToStr(wxGetTranslation(wxString::From8BitData(text))); } // Accessor for the main window class @@ -536,7 +536,7 @@ void Host_UpdateMainFrame() void Host_UpdateTitle(const char* title) { wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATETITLE); - event.SetString(wxString::FromAscii(title)); + event.SetString(StrToWxStr(title)); main_frame->GetEventHandler()->AddPendingEvent(event); } @@ -603,7 +603,7 @@ void Host_UpdateStatusBar(const char* _pText, int Field) { wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATESTATUSBAR); // Set the event string - event.SetString(wxString::FromAscii(_pText)); + event.SetString(StrToWxStr(_pText)); // Update statusbar field event.SetInt(Field); // Post message diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index b3a7ab22b8..d9fd4d3ae6 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -17,6 +17,8 @@ #include "MemcardManager.h" #include "Common.h" + +#include "WxUtils.h" #include "wx/mstream.h" #define ARROWS slot ? _T("") : ARROW[slot], slot ? ARROW[slot] : _T("") @@ -290,7 +292,7 @@ void CMemcardManager::ChangePath(int slot) } else { - if (m_MemcardPath[slot]->GetPath().length() && ReloadMemcard(m_MemcardPath[slot]->GetPath().mb_str(), slot)) + if (m_MemcardPath[slot]->GetPath().length() && ReloadMemcard(WxStrToStr(m_MemcardPath[slot]->GetPath()).c_str(), slot)) { if (memoryCard[slot2]) { @@ -345,7 +347,7 @@ void CMemcardManager::OnPageChange(wxCommandEvent& event) m_NextPage[slot]->Disable(); m_MemcardList[slot]->nextPage = false; } - ReloadMemcard(m_MemcardPath[slot]->GetPath().mb_str(), slot); + ReloadMemcard(WxStrToStr(m_MemcardPath[slot]->GetPath()).c_str(), slot); break; case ID_PREVPAGE_A: slot = SLOT_A; @@ -361,7 +363,7 @@ void CMemcardManager::OnPageChange(wxCommandEvent& event) m_PrevPage[slot]->Disable(); m_MemcardList[slot]->prevPage = false; } - ReloadMemcard(m_MemcardPath[slot]->GetPath().mb_str(), slot); + ReloadMemcard(WxStrToStr(m_MemcardPath[slot]->GetPath()).c_str(), slot); break; } } @@ -373,7 +375,7 @@ void CMemcardManager::OnMenuChange(wxCommandEvent& event) { case ID_MEMCARDPATH_A: case ID_MEMCARDPATH_B: - DefaultMemcard[_id - ID_MEMCARDPATH_A] = m_MemcardPath[_id - ID_MEMCARDPATH_A]->GetPath().mb_str(); + DefaultMemcard[_id - ID_MEMCARDPATH_A] = WxStrToStr(m_MemcardPath[_id - ID_MEMCARDPATH_A]->GetPath()); return; case ID_USEPAGES: mcmSettings.usePages = !mcmSettings.usePages; @@ -400,8 +402,8 @@ void CMemcardManager::OnMenuChange(wxCommandEvent& event) break; } - if (memoryCard[SLOT_A]) ReloadMemcard(m_MemcardPath[SLOT_A]->GetPath().mb_str(), SLOT_A); - if (memoryCard[SLOT_B]) ReloadMemcard(m_MemcardPath[SLOT_B]->GetPath().mb_str(), SLOT_B); + if (memoryCard[SLOT_A]) ReloadMemcard(WxStrToStr(m_MemcardPath[SLOT_A]->GetPath()).c_str(), SLOT_A); + if (memoryCard[SLOT_B]) ReloadMemcard(WxStrToStr(m_MemcardPath[SLOT_B]->GetPath()).c_str(), SLOT_B); } bool CMemcardManager::CopyDeleteSwitch(u32 error, int slot) { @@ -416,7 +418,7 @@ bool CMemcardManager::CopyDeleteSwitch(u32 error, int slot) memoryCard[slot]->FixChecksums(); if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED); page[slot] = FIRSTPAGE; - ReloadMemcard(m_MemcardPath[slot]->GetPath().mb_str(), slot); + ReloadMemcard(WxStrToStr(m_MemcardPath[slot]->GetPath()).c_str(), slot); } break; case NOMEMCARD: @@ -517,7 +519,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) wxString fileName = wxFileSelector( _("Select a save file to import"), (strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0) - ? wxString::FromAscii("") + ? StrToWxStr("") : wxString::From8BitData(DefaultIOPath.c_str()), wxEmptyString, wxEmptyString, _("GameCube Savegame files(*.gci;*.gcs;*.sav)") + wxString(wxT("|*.gci;*.gcs;*.sav|")) + @@ -532,11 +534,11 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) _("GCI File(*.gci)") + wxString(_T("|*.gci")), wxFD_OVERWRITE_PROMPT|wxFD_SAVE, this); if (temp2.empty()) break; - fileName2 = temp2.mb_str(); + fileName2 = WxStrToStr(temp2); } if (fileName.length() > 0) { - CopyDeleteSwitch(memoryCard[slot]->ImportGci(fileName.mb_str(), fileName2), slot); + CopyDeleteSwitch(memoryCard[slot]->ImportGci(WxStrToStr(fileName).c_str(), fileName2), slot); } } break; @@ -564,9 +566,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) if (fileName.length() > 0) { - if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), ""), -1)) + if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, WxStrToStr(fileName).c_str(), ""), -1)) { - File::Delete(std::string(fileName.mb_str())); + File::Delete(WxStrToStr(fileName)); } } } @@ -576,7 +578,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) case ID_EXPORTALL_B: { std::string path1, path2, mpath; - mpath = m_MemcardPath[slot]->GetPath().mb_str(); + mpath = WxStrToStr(m_MemcardPath[slot]->GetPath()); SplitPath(mpath, &path1, &path2, NULL); path1 += path2; File::CreateDir(path1); diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 142a7ea00c..d9fd5e6ca0 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -18,6 +18,7 @@ #include #include +#include "WxUtils.h" #include "NetPlay.h" #include "NetWindow.h" #include "Frame.h" @@ -72,7 +73,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::string address; netplay_section.Get("Address", &address, "localhost"); - m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(address.c_str())); + m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(address.c_str())); wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"), wxDefaultPosition, wxDefaultSize); @@ -80,7 +81,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("ConnectPort", &port, "2626"); - m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(port.c_str())); + m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port.c_str())); wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect")); connect_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnJoin, this); @@ -113,7 +114,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("HostPort", &port, "2626"); - m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, wxString::FromAscii(port.c_str())); + m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port.c_str())); wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, _("Host")); host_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnHost, this); @@ -124,7 +125,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::istringstream ss(game_list->GetGameNames()); std::string game; while (std::getline(ss,game)) - m_game_lbox->Append(wxString(game.c_str(), *wxConvCurrent)); + m_game_lbox->Append(StrToWxStr(game)); wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT, 5); @@ -167,10 +168,10 @@ NetPlaySetupDiag::~NetPlaySetupDiag() inifile.Load(dolphin_ini); IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - netplay_section.Set("Nickname", m_nickname_text->GetValue().mb_str()); - netplay_section.Set("Address", m_connect_ip_text->GetValue().mb_str()); - netplay_section.Set("ConnectPort", m_connect_port_text->GetValue().mb_str()); - netplay_section.Set("HostPort", m_host_port_text->GetValue().mb_str()); + netplay_section.Set("Nickname", WxStrToStr(m_nickname_text->GetValue())); + netplay_section.Set("Address", WxStrToStr(m_connect_ip_text->GetValue())); + netplay_section.Set("ConnectPort", WxStrToStr(m_connect_port_text->GetValue())); + netplay_section.Set("HostPort", WxStrToStr(m_host_port_text->GetValue())); inifile.Save(dolphin_ini); main_frame->g_NetPlaySetupDiag = NULL; @@ -191,13 +192,13 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&) return; } - std::string game(m_game_lbox->GetStringSelection().mb_str()); + std::string game(WxStrToStr(m_game_lbox->GetStringSelection())); npd = new NetPlayDiag(m_parent, m_game_list, game, true); unsigned long port = 0; m_host_port_text->GetValue().ToULong(&port); netplay_ptr = new NetPlayServer(u16(port) - , std::string(m_nickname_text->GetValue().mb_str()), npd, game); + , WxStrToStr(m_nickname_text->GetValue()), npd, game); if (netplay_ptr->is_connected) { npd->Show(); @@ -222,8 +223,8 @@ void NetPlaySetupDiag::OnJoin(wxCommandEvent&) npd = new NetPlayDiag(m_parent, m_game_list, ""); unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); - netplay_ptr = new NetPlayClient(std::string(m_connect_ip_text->GetValue().mb_str()) - , (u16)port, npd, std::string(m_nickname_text->GetValue().mb_str())); + netplay_ptr = new NetPlayClient(WxStrToStr(m_connect_ip_text->GetValue()) + , (u16)port, npd, WxStrToStr(m_nickname_text->GetValue())); if (netplay_ptr->is_connected) { npd->Show(); @@ -250,7 +251,7 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game // top crap m_game_btn = new wxButton(panel, wxID_ANY, - wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")), + StrToWxStr(m_selected_game).Prepend(_(" Game : ")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); if (is_hosting) @@ -351,7 +352,7 @@ void NetPlayDiag::OnChat(wxCommandEvent&) if (s.Length()) { - netplay_ptr->SendChatMessage(std::string(s.mb_str())); + netplay_ptr->SendChatMessage(WxStrToStr(s)); m_chat_text->AppendText(s.Prepend(wxT(" >> ")).Append(wxT('\n'))); m_chat_msg_text->Clear(); } @@ -412,7 +413,7 @@ void NetPlayDiag::OnMsgChangeGame(const std::string& filename) { wxCommandEvent evt(wxEVT_THREAD, NP_GUI_EVT_CHANGE_GAME); // TODO: using a wxString in AddPendingEvent from another thread is unsafe i guess? - evt.SetString(wxString(filename.c_str(), *wxConvCurrent)); + evt.SetString(StrToWxStr(filename)); GetEventHandler()->AddPendingEvent(evt); } @@ -436,7 +437,7 @@ void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&) << time * (60.0f/1000) << "(60fps) / " << time * (50.0f/1000) << "(50fps) >\n"; - m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent)); + m_chat_text->AppendText(StrToWxStr(ss.str())); } void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) @@ -447,7 +448,7 @@ void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) std::ostringstream ss; ss << "< Pad Buffer: " << val << " >"; netplay_ptr->SendChatMessage(ss.str()); - m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent).Append(wxT('\n'))); + m_chat_text->AppendText(StrToWxStr(ss.str()).Append(wxT('\n'))); } void NetPlayDiag::OnQuit(wxCommandEvent&) @@ -468,7 +469,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) m_player_lbox->Clear(); std::istringstream ss(tmps); while (std::getline(ss, tmps)) - m_player_lbox->Append(wxString(tmps.c_str(), *wxConvCurrent)); + m_player_lbox->Append(StrToWxStr(tmps)); m_player_lbox->SetSelection(selection); @@ -477,7 +478,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) case NP_GUI_EVT_CHANGE_GAME : // update selected game :/ { - m_selected_game.assign(event.GetString().mb_str()); + m_selected_game.assign(WxStrToStr(event.GetString())); m_game_btn->SetLabel(event.GetString().Prepend(_(" Game : "))); } break; @@ -503,7 +504,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) std::string s; chat_msgs.Pop(s); //PanicAlert("message: %s", s.c_str()); - m_chat_text->AppendText(wxString(s.c_str(), *wxConvCurrent).Append(wxT('\n'))); + m_chat_text->AppendText(StrToWxStr(s).Append(wxT('\n'))); } } @@ -515,7 +516,7 @@ void NetPlayDiag::OnChangeGame(wxCommandEvent&) if (game_name.length()) { - m_selected_game = std::string(game_name.mb_str()); + m_selected_game = WxStrToStr(game_name); netplay_ptr->ChangeGame(m_selected_game); m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); } @@ -553,7 +554,7 @@ ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* cons std::istringstream ss(game_list->GetGameNames()); std::string game; while (std::getline(ss,game)) - m_game_lbox->Append(wxString(game.c_str(), *wxConvCurrent)); + m_game_lbox->Append(StrToWxStr(game)); wxButton* const ok_btn = new wxButton(this, wxID_OK, _("Change")); ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ChangeGameDiag::OnPick, this); diff --git a/Source/Core/DolphinWX/Src/PHackSettings.cpp b/Source/Core/DolphinWX/Src/PHackSettings.cpp index 83f08d9cb7..dcfa1a8501 100644 --- a/Source/Core/DolphinWX/Src/PHackSettings.cpp +++ b/Source/Core/DolphinWX/Src/PHackSettings.cpp @@ -17,6 +17,7 @@ #include "PHackSettings.h" #include "ConfigManager.h" +#include "WxUtils.h" extern PHackData PHack_Data; @@ -97,8 +98,8 @@ void CPHackSettings::LoadPHackData() if (sTemp.empty()) sTemp = wxString(_("(UNKNOWN)")).char_str(); if (i == 0) - PHackChoice->Append(wxString("-------------", *wxConvCurrent)); - PHackChoice->Append(wxString(sTemp.c_str(), *wxConvCurrent)); + PHackChoice->Append(StrToWxStr("-------------")); + PHackChoice->Append(StrToWxStr(sTemp)); } PHackChoice->Select(0); @@ -106,8 +107,8 @@ void CPHackSettings::LoadPHackData() PHackSZFar->Set3StateValue((wxCheckBoxState)PHack_Data.PHackSZFar); PHackExP->Set3StateValue((wxCheckBoxState)PHack_Data.PHackExP); - PHackZNear->SetValue(wxString(PHack_Data.PHZNear.c_str(), *wxConvCurrent)); - PHackZFar->SetValue(wxString(PHack_Data.PHZFar.c_str(), *wxConvCurrent)); + PHackZNear->SetValue(StrToWxStr(PHack_Data.PHZNear)); + PHackZFar->SetValue(StrToWxStr(PHack_Data.PHZFar)); } void CPHackSettings::SetRefresh(wxCommandEvent& event) @@ -128,9 +129,9 @@ void CPHackSettings::SetRefresh(wxCommandEvent& event) PHPresetsIni.Get(sIndex, "PH_ExtraParam", &bTemp); PHackExP->Set3StateValue((wxCheckBoxState)bTemp); PHPresetsIni.Get(sIndex, "PH_ZNear", &sTemp); - PHackZNear->SetValue(wxString(sTemp.c_str(), *wxConvCurrent)); + PHackZNear->SetValue(StrToWxStr(sTemp)); PHPresetsIni.Get(sIndex, "PH_ZFar", &sTemp); - PHackZFar->SetValue(wxString(sTemp.c_str(), *wxConvCurrent)); + PHackZFar->SetValue(StrToWxStr(sTemp)); } } diff --git a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp index 7d521006d3..3199240d74 100644 --- a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp +++ b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "PatchAddEdit.h" +#include "WxUtils.h" extern std::vector onFrame; @@ -48,7 +49,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection) } else { - currentName = wxString(onFrame.at(_selection).name.c_str(), *wxConvCurrent); + currentName = StrToWxStr(onFrame.at(_selection).name.c_str()); tempEntries = onFrame.at(_selection).entries; } @@ -66,7 +67,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection) EntrySelection->SetValue((int)tempEntries.size()-1); wxArrayString wxArrayStringFor_EditPatchType; for (int i = 0; i < 3; ++i) - wxArrayStringFor_EditPatchType.Add(wxString::FromAscii(PatchEngine::PatchTypeStrings[i])); + wxArrayStringFor_EditPatchType.Add(StrToWxStr(PatchEngine::PatchTypeStrings[i])); EditPatchType = new wxRadioBox(this, ID_EDITPATCH_TYPE, _("Type"), wxDefaultPosition, wxDefaultSize, wxArrayStringFor_EditPatchType, 3, wxRA_SPECIFY_COLS); EditPatchType->SetSelection((int)tempEntries.at(0).type); wxStaticText* EditPatchValueText = new wxStaticText(this, ID_EDITPATCH_VALUE_TEXT, _("Value:")); @@ -121,7 +122,7 @@ void CPatchAddEdit::SavePatchData(wxCommandEvent& event) if (selection == -1) { PatchEngine::Patch newPatch; - newPatch.name = std::string(EditPatchName->GetValue().mb_str()); + newPatch.name = WxStrToStr(EditPatchName->GetValue()); newPatch.entries = tempEntries; newPatch.active = true; @@ -129,7 +130,7 @@ void CPatchAddEdit::SavePatchData(wxCommandEvent& event) } else { - onFrame.at(selection).name = std::string(EditPatchName->GetValue().mb_str()); + onFrame.at(selection).name = WxStrToStr(EditPatchName->GetValue()); onFrame.at(selection).entries = tempEntries; } diff --git a/Source/Core/DolphinWX/Src/UDPConfigDiag.cpp b/Source/Core/DolphinWX/Src/UDPConfigDiag.cpp index 2f31311495..9619f38dee 100644 --- a/Source/Core/DolphinWX/Src/UDPConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/UDPConfigDiag.cpp @@ -4,6 +4,8 @@ #include "Common.h" #include "ControllerEmu.h" #include "IniFile.h" +#include "WxUtils.h" + #include UDPConfigDiag::UDPConfigDiag(wxWindow * const parent, UDPWrapper * _wrp) : @@ -26,7 +28,7 @@ UDPConfigDiag::UDPConfigDiag(wxWindow * const parent, UDPWrapper * _wrp) : wxBoxSizer *const port_sizer = new wxBoxSizer(wxHORIZONTAL); port_sizer->Add(new wxStaticText(this, wxID_ANY, _("UDP Port:")), 0, wxALIGN_CENTER); - port_tbox = new wxTextCtrl(this, wxID_ANY, wxString::FromUTF8(wrp->port.c_str())); + port_tbox = new wxTextCtrl(this, wxID_ANY, StrToWxStr(wrp->port)); port_sizer->Add(port_tbox, 1, wxLEFT | wxEXPAND, 5); enable->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &UDPConfigDiag::ChangeState, this); @@ -71,7 +73,7 @@ void UDPConfigDiag::ChangeUpdateFlags(wxCommandEvent & WXUNUSED(event)) void UDPConfigDiag::ChangeState(wxCommandEvent & WXUNUSED(event)) { - wrp->udpEn=enable->GetValue(); - wrp->port=port_tbox->GetValue().mb_str(wxConvUTF8); + wrp->udpEn = enable->GetValue(); + wrp->port = WxStrToStr(port_tbox->GetValue()); wrp->Refresh(); } diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp index 0ca4715c3d..7c8a3b7e04 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp @@ -141,7 +141,7 @@ wxArrayString GetListOfResolutions() if (std::find(resos.begin(), resos.end(), strRes) == resos.end()) { resos.push_back(strRes); - retlist.Add(wxString::FromAscii(res)); + retlist.Add(StrToWxStr(res)); } ZeroMemory(&dmi, sizeof(dmi)); } @@ -212,9 +212,9 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = g_available_video_backends.begin(), itend = g_available_video_backends.end(); for (; it != itend; ++it) - choice_backend->AppendString(wxGetTranslation(wxString::FromAscii((*it)->GetName().c_str()))); + choice_backend->AppendString(wxGetTranslation(StrToWxStr((*it)->GetName().c_str()))); - choice_backend->SetStringSelection(wxGetTranslation(wxString::FromAscii(g_video_backend->GetName().c_str()))); + choice_backend->SetStringSelection(wxGetTranslation(StrToWxStr(g_video_backend->GetName().c_str()))); choice_backend->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_Backend, this); szr_basic->Add(label_backend, 1, wxALIGN_CENTER_VERTICAL, 5); @@ -236,7 +236,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.Adapters.begin(), itend = vconfig.backend_info.Adapters.end(); for (; it != itend; ++it) - choice_adapter->AppendString(wxString::FromAscii(it->c_str())); + choice_adapter->AppendString(StrToWxStr(it->c_str())); choice_adapter->Select(vconfig.iAdapter); @@ -259,7 +259,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con RegisterControl(choice_display_resolution, wxGetTranslation(display_res_desc)); choice_display_resolution->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_DisplayResolution, this); - choice_display_resolution->SetStringSelection(wxString::FromAscii(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution.c_str())); + choice_display_resolution->SetStringSelection(StrToWxStr(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution.c_str())); szr_display->Add(label_display_resolution, 1, wxALIGN_CENTER_VERTICAL, 0); szr_display->Add(choice_display_resolution); @@ -355,7 +355,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.AAModes.begin(), itend = vconfig.backend_info.AAModes.end(); for (; it != itend; ++it) - choice_aamode->AppendString(wxGetTranslation(wxString::FromAscii(it->c_str()))); + choice_aamode->AppendString(wxGetTranslation(StrToWxStr(it->c_str()))); choice_aamode->Select(vconfig.iMultisampleMode); szr_enh->Add(text_aamode, 1, wxALIGN_CENTER_VERTICAL, 0); @@ -380,12 +380,12 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.PPShaders.begin(), itend = vconfig.backend_info.PPShaders.end(); for (; it != itend; ++it) - choice_ppshader->AppendString(wxString::FromAscii(it->c_str())); + choice_ppshader->AppendString(StrToWxStr(it->c_str())); if (vconfig.sPostProcessingShader.empty()) choice_ppshader->Select(0); else - choice_ppshader->SetStringSelection(wxString::FromAscii(vconfig.sPostProcessingShader.c_str())); + choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader.c_str())); choice_ppshader->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_PPShader, this); @@ -595,7 +595,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con void VideoConfigDiag::Event_DisplayResolution(wxCommandEvent &ev) { SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution = - choice_display_resolution->GetStringSelection().mb_str(); + WxStrToStr(choice_display_resolution->GetStringSelection()); #if defined(HAVE_XRANDR) && HAVE_XRANDR main_frame->m_XRRConfig->Update(); #endif diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.h b/Source/Core/DolphinWX/Src/VideoConfigDiag.h index c7a19c6cb8..8507fffdc1 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.h +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.h @@ -20,6 +20,7 @@ #include #include "MsgHandler.h" +#include "WxUtils.h" template class BoolSetting : public W @@ -99,7 +100,7 @@ protected: else { // Select current backend again - choice_backend->SetStringSelection(wxString::FromAscii(g_video_backend->GetName().c_str())); + choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName().c_str())); } } @@ -129,7 +130,7 @@ protected: { const int sel = ev.GetInt(); if (sel) - vconfig.sPostProcessingShader = ev.GetString().mb_str(); + vconfig.sPostProcessingShader = WxStrToStr(ev.GetString()); else vconfig.sPostProcessingShader.clear(); diff --git a/Source/Core/DolphinWX/Src/WxUtils.cpp b/Source/Core/DolphinWX/Src/WxUtils.cpp index 22fa10b84d..ee6f815648 100644 --- a/Source/Core/DolphinWX/Src/WxUtils.cpp +++ b/Source/Core/DolphinWX/Src/WxUtils.cpp @@ -20,12 +20,14 @@ #include #include +#include "WxUtils.h" + namespace WxUtils { // Launch a file according to its mime type void Launch(const char *filename) { - if (! ::wxLaunchDefaultBrowser(wxString(filename, *wxConvCurrent))) + if (! ::wxLaunchDefaultBrowser(StrToWxStr(filename))) { // WARN_LOG } @@ -34,7 +36,7 @@ void Launch(const char *filename) // Launch an file explorer window on a certain path void Explore(const char *path) { - wxString wxPath = wxString(path, *wxConvCurrent); + wxString wxPath = StrToWxStr(path); // Default to file if (! wxPath.Contains(wxT("://"))) { @@ -52,3 +54,13 @@ void Explore(const char *path) } } // namespace + +std::string WxStrToStr(const wxString& str) +{ + return str.ToUTF8(); +} + +wxString StrToWxStr(const std::string& str) +{ + return wxString::FromUTF8(str.c_str()); +} diff --git a/Source/Core/DolphinWX/Src/WxUtils.h b/Source/Core/DolphinWX/Src/WxUtils.h index 8e837e9e96..61a16b298e 100644 --- a/Source/Core/DolphinWX/Src/WxUtils.h +++ b/Source/Core/DolphinWX/Src/WxUtils.h @@ -18,7 +18,11 @@ #ifndef WXUTILS_H #define WXUTILS_H -namespace WxUtils { +#include +#include + +namespace WxUtils +{ // Launch a file according to its mime type void Launch(const char *filename); @@ -28,4 +32,7 @@ void Explore(const char *path); } // namespace +std::string WxStrToStr(const wxString& str); +wxString StrToWxStr(const std::string& str); + #endif // WXUTILS diff --git a/Source/Core/DolphinWX/Src/X11Utils.cpp b/Source/Core/DolphinWX/Src/X11Utils.cpp index f032f81e96..3582b9b576 100644 --- a/Source/Core/DolphinWX/Src/X11Utils.cpp +++ b/Source/Core/DolphinWX/Src/X11Utils.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "X11Utils.h" +#include "WxUtils.h" #include #include @@ -350,7 +351,7 @@ void XRRConfiguration::AddResolutions(wxArrayString& arrayStringFor_FullscreenRe if (std::find(resos.begin(), resos.end(), strRes) == resos.end()) { resos.push_back(strRes); - arrayStringFor_FullscreenResolution.Add(wxString::FromUTF8(strRes.c_str())); + arrayStringFor_FullscreenResolution.Add(StrToWxStr(strRes)); } } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index b5393cdbde..d0bb94a39a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -24,6 +24,7 @@ #include #include "GLUtil.h" +#include "WxUtils.h" #include "FileUtil.h" @@ -1538,7 +1539,7 @@ void TakeScreenshot(ScrStrct* threadStruct) // Save the screenshot and finally kill the wxImage object // This is really expensive when saving to PNG, but not at all when using BMP - threadStruct->img->SaveFile(wxString::FromAscii(threadStruct->filename.c_str()), + threadStruct->img->SaveFile(StrToWxStr(threadStruct->filename.c_str()), wxBITMAP_TYPE_PNG); threadStruct->img->Destroy(); diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp index bd085a3edf..670c3f9c6d 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp @@ -34,7 +34,7 @@ IntegerSetting::IntegerSetting(wxWindow* parent, const wxString& label, T& se VideoConfigDialog::VideoConfigDialog(wxWindow* parent, const std::string& title, const std::string& _ininame) : wxDialog(parent, -1, - wxString(wxT("Dolphin ")).append(wxString::FromAscii(title.c_str())).append(wxT(" Graphics Configuration")), + wxString(wxT("Dolphin ")).append(StrToWxStr(title.c_str())).append(wxT(" Graphics Configuration")), wxDefaultPosition, wxDefaultSize), vconfig(g_SWVideoConfig), ininame(_ininame) @@ -64,10 +64,10 @@ VideoConfigDialog::VideoConfigDialog(wxWindow* parent, const std::string& title, it = g_available_video_backends.begin(), itend = g_available_video_backends.end(); for (; it != itend; ++it) - choice_backend->AppendString(wxString::FromAscii((*it)->GetName().c_str())); + choice_backend->AppendString(StrToWxStr((*it)->GetName())); // TODO: How to get the translated plugin name? - choice_backend->SetStringSelection(wxString::FromAscii(g_video_backend->GetName().c_str())); + choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName())); choice_backend->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDialog::Event_Backend, this); szr_rendering->Add(label_backend, 1, wxALIGN_CENTER_VERTICAL, 5); From 03ec9a2e088b0818bf02a5bc2ffda4a512cba2b7 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 28 Feb 2013 02:39:06 -0600 Subject: [PATCH 09/26] Kill some unnecessary c_str and use StrToWxStr in a few places that I missed. --- Source/Core/DolphinWX/Src/AboutDolphin.cpp | 2 +- Source/Core/DolphinWX/Src/CheatsWindow.cpp | 2 +- Source/Core/DolphinWX/Src/ConfigMain.cpp | 9 +++++---- Source/Core/DolphinWX/Src/Debugger/CodeView.cpp | 4 ++-- .../Core/DolphinWX/Src/Debugger/CodeWindow.cpp | 2 +- .../Src/Debugger/CodeWindowFunctions.cpp | 4 ++-- .../DolphinWX/Src/Debugger/DSPDebugWindow.cpp | 2 +- Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp | 16 ++++++++-------- Source/Core/DolphinWX/Src/FrameAui.cpp | 4 ++-- Source/Core/DolphinWX/Src/FrameTools.cpp | 2 +- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 10 +++++----- Source/Core/DolphinWX/Src/ISOProperties.cpp | 8 ++++---- Source/Core/DolphinWX/Src/InputConfigDiag.cpp | 8 ++++---- .../DolphinWX/Src/InputConfigDiagBitmaps.cpp | 4 ++-- Source/Core/DolphinWX/Src/NetWindow.cpp | 6 +++--- Source/Core/DolphinWX/Src/PatchAddEdit.cpp | 2 +- Source/Core/DolphinWX/Src/VideoConfigDiag.cpp | 14 +++++++------- Source/Core/DolphinWX/Src/VideoConfigDiag.h | 2 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 2 +- .../Src/VideoConfigDialog.cpp | 2 +- 20 files changed, 53 insertions(+), 52 deletions(-) diff --git a/Source/Core/DolphinWX/Src/AboutDolphin.cpp b/Source/Core/DolphinWX/Src/AboutDolphin.cpp index eeecf18d48..5126274601 100644 --- a/Source/Core/DolphinWX/Src/AboutDolphin.cpp +++ b/Source/Core/DolphinWX/Src/AboutDolphin.cpp @@ -63,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, - StrToWxStr(Text.c_str())); + StrToWxStr(Text)); Message->Wrap(GetSize().GetWidth()); wxBoxSizer* const sInfo = new wxBoxSizer(wxVERTICAL); diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.cpp b/Source/Core/DolphinWX/Src/CheatsWindow.cpp index 1e0f714467..fb3c3cbb23 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Src/CheatsWindow.cpp @@ -348,7 +348,7 @@ void wxCheatsWindow::OnEvent_ButtonUpdateLog_Press(wxCommandEvent& WXUNUSED (eve const std::vector &arLog = ActionReplay::GetSelfLog(); for (u32 i = 0; i < arLog.size(); i++) { - m_TextCtrl_Log->AppendText(StrToWxStr(arLog[i].c_str())); + m_TextCtrl_Log->AppendText(StrToWxStr(arLog[i])); } } diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index bdb4cdc7fe..068501c432 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -982,9 +982,9 @@ void CConfigMain::AddAudioBackends() for (std::vector::const_iterator iter = backends.begin(); iter != backends.end(); ++iter) { - BackendSelection->Append(StrToWxStr((*iter).c_str())); + BackendSelection->Append(StrToWxStr(*iter)); int num = BackendSelection->\ - FindString(StrToWxStr(SConfig::GetInstance().sBackend.c_str())); + FindString(StrToWxStr(SConfig::GetInstance().sBackend)); BackendSelection->SetSelection(num); } } @@ -1269,8 +1269,9 @@ void CConfigMain::ApploaderPathChanged(wxFileDirPickerEvent& WXUNUSED (event)) void CConfigMain::NANDRootChanged(wxFileDirPickerEvent& WXUNUSED (event)) { std::string NANDPath = - SConfig::GetInstance().m_NANDPath = File::GetUserPath(D_WIIROOT_IDX, WxStrToStr(NANDRoot->GetPath())); - NANDRoot->SetPath(wxString(NANDPath)); + 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(); diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp index 3b22ca339d..31ad19d6da 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeView.cpp @@ -253,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(StrToWxStr(text.c_str()))); + wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text))); } } break; @@ -300,7 +300,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event) { wxTextEntryDialog input_symbol(this, StrToWxStr("Rename symbol:"), wxGetTextFromUserPromptStr, - StrToWxStr(symbol->name.c_str())); + StrToWxStr(symbol->name)); if (input_symbol.ShowModal() == wxID_OK) { symbol->name = WxStrToStr(input_symbol.GetValue()); diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp index 1cff07c0f4..9172a3af9a 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp @@ -345,7 +345,7 @@ void CCodeWindow::UpdateCallstack() for (size_t i = 0; i < stack.size(); i++) { - int idx = callstack->Append(StrToWxStr(stack[i].Name.c_str())); + int idx = callstack->Append(StrToWxStr(stack[i].Name)); callstack->SetClientData(idx, (void*)(u64)stack[i].vAddress); } diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index a11783c010..7ec36131ff 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -66,7 +66,7 @@ void CCodeWindow::Load() std::string fontDesc; ini.Get("General", "DebuggerFont", &fontDesc); if (!fontDesc.empty()) - DebuggerFont.SetNativeFontInfoUserDesc(StrToWxStr(fontDesc.c_str())); + DebuggerFont.SetNativeFontInfoUserDesc(StrToWxStr(fontDesc)); // Boot to pause or not ini.Get("General", "AutomaticStart", &bAutomaticStart, false); @@ -366,7 +366,7 @@ void CCodeWindow::NotifyMapLoaded() symbols->Clear(); for (PPCSymbolDB::XFuncMap::iterator iter = g_symbolDB.GetIterator(); iter != g_symbolDB.End(); ++iter) { - int idx = symbols->Append(StrToWxStr(iter->second.name.c_str())); + int idx = symbols->Append(StrToWxStr(iter->second.name)); symbols->SetClientData(idx, (void*)&iter->second); } symbols->Thaw(); diff --git a/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp index 27da055990..e77b57399e 100644 --- a/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp @@ -221,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(StrToWxStr(iter->second.name.c_str())); + int idx = m_SymbolList->Append(StrToWxStr(iter->second.name)); m_SymbolList->SetClientData(idx, (void*)&iter->second); } m_SymbolList->Thaw(); diff --git a/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp index e80d206112..7f98af6c57 100644 --- a/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp @@ -120,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; } @@ -151,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; @@ -190,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; diff --git a/Source/Core/DolphinWX/Src/FrameAui.cpp b/Source/Core/DolphinWX/Src/FrameAui.cpp index fd3cbb662b..6f10d46722 100644 --- a/Source/Core/DolphinWX/Src/FrameAui.cpp +++ b/Source/Core/DolphinWX/Src/FrameAui.cpp @@ -549,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, - StrToWxStr(Perspectives[i].Name.c_str()), + StrToWxStr(Perspectives[i].Name), wxT(""), wxITEM_CHECK); menuPopup->Append(mItem); if (i == ActivePerspective) mItem->Check(true); @@ -871,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 = StrToWxStr(_Perspective.c_str()); + Tmp.Perspective = StrToWxStr(_Perspective); SplitString(_Width, ',', _SWidth); SplitString(_Height, ',', _SHeight); diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index a1dcd959fe..4b1fc820a9 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -101,7 +101,7 @@ void CFrame::CreateMenu() drives = cdio_get_devices(); // Windows Limitation of 24 character drives for (unsigned int i = 0; i < drives.size() && i < 24; i++) { - externalDrive->Append(IDM_DRIVE1 + i, StrToWxStr(drives[i].c_str())); + externalDrive->Append(IDM_DRIVE1 + i, StrToWxStr(drives[i])); } fileMenu->AppendSeparator(); diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index d385b947e5..cab4c8125b 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -614,7 +614,7 @@ void CGameListCtrl::ScanForISOs() // Update with the progress (i) and the message dialog.Update(i, wxString::Format(_("Scanning %s"), - StrToWxStr(FileName).c_str())); + StrToWxStr(FileName))); if (dialog.WasCancelled()) break; @@ -1173,10 +1173,10 @@ void CGameListCtrl::CompressSelection(bool _compress) WxStrToStr(browseDialog.GetPath()), FileName); - if (wxFileExists(StrToWxStr(OutputFileName.c_str())) && + if (wxFileExists(StrToWxStr(OutputFileName)) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), - StrToWxStr(OutputFileName).c_str()), + StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; @@ -1201,10 +1201,10 @@ void CGameListCtrl::CompressSelection(bool _compress) WxStrToStr(browseDialog.GetPath()), FileName); - if (wxFileExists(StrToWxStr(OutputFileName.c_str())) && + if (wxFileExists(StrToWxStr(OutputFileName)) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), - StrToWxStr(OutputFileName).c_str()), + StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index e739ff043b..6434c8cd54 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -728,7 +728,7 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde (u32)(((float)(i - index[0]) / (float)(index[1] - index[0])) * 100))); dialog.Update(i, wxString::Format(_("Extracting %s"), - StrToWxStr(fst[i]->m_FullPath).c_str())); + StrToWxStr(fst[i]->m_FullPath))); if (dialog.WasCancelled()) break; @@ -990,7 +990,7 @@ void CISOProperties::LoadGameConfig() GameIni.Get("EmuState", "EmulationIssues", &sTemp); if (!sTemp.empty()) { - EmuIssues->SetValue(StrToWxStr(sTemp.c_str())); + EmuIssues->SetValue(StrToWxStr(sTemp)); } EmuIssues->Enable(EmuState->GetSelection() != 0); @@ -1157,7 +1157,7 @@ void CISOProperties::PatchList_Load() for (std::vector::const_iterator it = onFrame.begin(); it != onFrame.end(); ++it) { PatchEngine::Patch p = *it; - Patches->Append(StrToWxStr(p.name.c_str())); + Patches->Append(StrToWxStr(p.name)); Patches->Check(index, p.active); ++index; } @@ -1366,5 +1366,5 @@ void CISOProperties::ChangeBannerDetails(int lang) SplitPath(OpenGameListItem->GetFileName(), 0, &filename, &extension); // Also sets the window's title SetTitle(StrToWxStr(StringFromFormat("%s%s: %s - ", filename.c_str(), - extension.c_str(), OpenGameListItem->GetUniqueID().c_str()).c_str()) + shortName); + extension.c_str(), OpenGameListItem->GetUniqueID().c_str())) + shortName); } diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp index d8a755aca6..1df215fb1e 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp @@ -34,7 +34,7 @@ void GamepadPage::ConfigExtension(wxCommandEvent& event) if (ex->switch_extension) { wxDialog dlg(this, -1, - StrToWxStr(ex->attachments[ex->switch_extension]->GetName().c_str()), + StrToWxStr(ex->attachments[ex->switch_extension]->GetName()), wxDefaultPosition, wxDefaultSize); wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL); @@ -64,7 +64,7 @@ PadSettingExtension::PadSettingExtension(wxWindow* const parent, ControllerEmu:: e = extension->attachments.end(); for (; i!=e; ++i) - ((wxChoice*)wxcontrol)->Append(StrToWxStr((*i)->GetName().c_str())); + ((wxChoice*)wxcontrol)->Append(StrToWxStr((*i)->GetName())); UpdateGUI(); } @@ -612,7 +612,7 @@ void GamepadPage::DeleteProfile(wxCommandEvent&) if (File::Exists(fnamecstr) && AskYesNoT("Are you sure you want to delete \"%s\"?", - WxStrToStr(profile_cbox->GetValue()).c_str())) + WxStrToStr(profile_cbox->GetValue()))) { File::Delete(fnamecstr); @@ -952,7 +952,7 @@ GamepadPage::GamepadPage(wxWindow* parent, InputPlugin& plugin, const unsigned i InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputPlugin& plugin, const std::string& name, const int tab_num) - : wxDialog(parent, wxID_ANY, StrToWxStr(name.c_str()), wxPoint(128,-1), wxDefaultSize) + : wxDialog(parent, wxID_ANY, StrToWxStr(name), wxPoint(128,-1), wxDefaultSize) , m_plugin(plugin) { m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT); diff --git a/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp b/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp index 4e07ed990d..efb7db59af 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiagBitmaps.cpp @@ -228,7 +228,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) // text const char* const name = (*g)->control_group->controls[n]->name; // bit of hax so ZL, ZR show up as L, R - dc.DrawText(StrToWxStr((name[1] && name[1] < 'a') ? name[1] : name[0]), n*12 + 2, 1); + dc.DrawText(StrToWxStr(std::string(1, (name[1] && name[1] < 'a') ? name[1] : name[0])), n*12 + 2, 1); } delete[] bitmasks; @@ -300,7 +300,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) // text dc.DrawText(StrToWxStr((*g)->control_group->controls[n+trigger_count]->name), 3, n*12 + 1); - dc.DrawText(StrToWxStr((*g)->control_group->controls[n]->name[0]), 64 + 3, n*12 + 1); + dc.DrawText(StrToWxStr(std::string(1, (*g)->control_group->controls[n]->name[0])), 64 + 3, n*12 + 1); } // threshold box diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index d9fd5e6ca0..988ccae83e 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -73,7 +73,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::string address; netplay_section.Get("Address", &address, "localhost"); - m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(address.c_str())); + m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(address)); wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"), wxDefaultPosition, wxDefaultSize); @@ -81,7 +81,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("ConnectPort", &port, "2626"); - m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port.c_str())); + m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port)); wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect")); connect_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnJoin, this); @@ -114,7 +114,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("HostPort", &port, "2626"); - m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port.c_str())); + m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port)); wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, _("Host")); host_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnHost, this); diff --git a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp index 3199240d74..ead7918d34 100644 --- a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp +++ b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp @@ -49,7 +49,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection) } else { - currentName = StrToWxStr(onFrame.at(_selection).name.c_str()); + currentName = StrToWxStr(onFrame.at(_selection).name); tempEntries = onFrame.at(_selection).entries; } diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp index 7c8a3b7e04..154a5bc602 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp @@ -212,9 +212,9 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = g_available_video_backends.begin(), itend = g_available_video_backends.end(); for (; it != itend; ++it) - choice_backend->AppendString(wxGetTranslation(StrToWxStr((*it)->GetName().c_str()))); + choice_backend->AppendString(wxGetTranslation(StrToWxStr((*it)->GetName()))); - choice_backend->SetStringSelection(wxGetTranslation(StrToWxStr(g_video_backend->GetName().c_str()))); + choice_backend->SetStringSelection(wxGetTranslation(StrToWxStr(g_video_backend->GetName()))); choice_backend->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_Backend, this); szr_basic->Add(label_backend, 1, wxALIGN_CENTER_VERTICAL, 5); @@ -236,7 +236,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.Adapters.begin(), itend = vconfig.backend_info.Adapters.end(); for (; it != itend; ++it) - choice_adapter->AppendString(StrToWxStr(it->c_str())); + choice_adapter->AppendString(StrToWxStr(*it)); choice_adapter->Select(vconfig.iAdapter); @@ -259,7 +259,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con RegisterControl(choice_display_resolution, wxGetTranslation(display_res_desc)); choice_display_resolution->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_DisplayResolution, this); - choice_display_resolution->SetStringSelection(StrToWxStr(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution.c_str())); + choice_display_resolution->SetStringSelection(StrToWxStr(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution)); szr_display->Add(label_display_resolution, 1, wxALIGN_CENTER_VERTICAL, 0); szr_display->Add(choice_display_resolution); @@ -355,7 +355,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.AAModes.begin(), itend = vconfig.backend_info.AAModes.end(); for (; it != itend; ++it) - choice_aamode->AppendString(wxGetTranslation(StrToWxStr(it->c_str()))); + choice_aamode->AppendString(wxGetTranslation(StrToWxStr(*it))); choice_aamode->Select(vconfig.iMultisampleMode); szr_enh->Add(text_aamode, 1, wxALIGN_CENTER_VERTICAL, 0); @@ -380,12 +380,12 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con it = vconfig.backend_info.PPShaders.begin(), itend = vconfig.backend_info.PPShaders.end(); for (; it != itend; ++it) - choice_ppshader->AppendString(StrToWxStr(it->c_str())); + choice_ppshader->AppendString(StrToWxStr(*it)); if (vconfig.sPostProcessingShader.empty()) choice_ppshader->Select(0); else - choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader.c_str())); + choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader)); choice_ppshader->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDiag::Event_PPShader, this); diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.h b/Source/Core/DolphinWX/Src/VideoConfigDiag.h index 8507fffdc1..90a42c34a1 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.h +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.h @@ -100,7 +100,7 @@ protected: else { // Select current backend again - choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName().c_str())); + choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName())); } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index d0bb94a39a..f0213578c5 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -1539,7 +1539,7 @@ void TakeScreenshot(ScrStrct* threadStruct) // Save the screenshot and finally kill the wxImage object // This is really expensive when saving to PNG, but not at all when using BMP - threadStruct->img->SaveFile(StrToWxStr(threadStruct->filename.c_str()), + threadStruct->img->SaveFile(StrToWxStr(threadStruct->filename), wxBITMAP_TYPE_PNG); threadStruct->img->Destroy(); diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp index 670c3f9c6d..e7122d2f71 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/VideoConfigDialog.cpp @@ -34,7 +34,7 @@ IntegerSetting::IntegerSetting(wxWindow* parent, const wxString& label, T& se VideoConfigDialog::VideoConfigDialog(wxWindow* parent, const std::string& title, const std::string& _ininame) : wxDialog(parent, -1, - wxString(wxT("Dolphin ")).append(StrToWxStr(title.c_str())).append(wxT(" Graphics Configuration")), + wxString(wxT("Dolphin ")).append(StrToWxStr(title)).append(wxT(" Graphics Configuration")), wxDefaultPosition, wxDefaultSize), vconfig(g_SWVideoConfig), ininame(_ininame) From 95558cdc6911e6122fec94616e4d6975d2c355fb Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 28 Feb 2013 03:11:10 -0600 Subject: [PATCH 10/26] Buildfix. --- Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp | 2 +- Source/Core/DolphinWX/Src/InputConfigDiag.cpp | 2 +- Source/Core/DolphinWX/Src/WxUtils.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index 7ec36131ff..362e617696 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -285,7 +285,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event) if (!path.IsEmpty()) { - std::ifstream f(WxStrToStr(path)); + std::ifstream f(WxStrToStr(path).c_str()); std::string line; while (std::getline(f, line)) diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp index 1df215fb1e..14772d8676 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp @@ -612,7 +612,7 @@ void GamepadPage::DeleteProfile(wxCommandEvent&) if (File::Exists(fnamecstr) && AskYesNoT("Are you sure you want to delete \"%s\"?", - WxStrToStr(profile_cbox->GetValue()))) + WxStrToStr(profile_cbox->GetValue()).c_str())) { File::Delete(fnamecstr); diff --git a/Source/Core/DolphinWX/Src/WxUtils.cpp b/Source/Core/DolphinWX/Src/WxUtils.cpp index ee6f815648..6856c96481 100644 --- a/Source/Core/DolphinWX/Src/WxUtils.cpp +++ b/Source/Core/DolphinWX/Src/WxUtils.cpp @@ -57,10 +57,11 @@ void Explore(const char *path) std::string WxStrToStr(const wxString& str) { - return str.ToUTF8(); + return str.ToUTF8().data(); } wxString StrToWxStr(const std::string& str) { + //return wxString::FromUTF8Unchecked(str.c_str()); return wxString::FromUTF8(str.c_str()); } From dea1e2827d6ce6eb5f6bfe2c64c59a36b3606b02 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 28 Feb 2013 19:33:39 -0600 Subject: [PATCH 11/26] Open std::fstream in a unicode-safe manner. --- Source/Core/Common/Src/FileUtil.h | 12 ++++++++++++ Source/Core/Common/Src/IniFile.cpp | 5 +++-- Source/Core/Common/Src/LinearDiskCache.h | 2 +- Source/Core/Common/Src/LogManager.cpp | 2 +- Source/Core/Common/Src/NandPaths.cpp | 6 ++++-- Source/Core/Core/Src/DSP/assemble.cpp | 3 ++- .../Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp | 2 +- Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp | 2 +- .../DolphinWX/Src/Debugger/CodeWindowFunctions.cpp | 3 ++- Source/Core/DolphinWX/Src/ISOProperties.cpp | 3 ++- Source/Core/VideoCommon/Src/ImageWrite.cpp | 3 ++- Source/Core/VideoCommon/Src/PixelShaderGen.cpp | 3 ++- Source/Core/VideoCommon/Src/VertexManagerBase.cpp | 6 ++++-- Source/Core/VideoCommon/Src/VertexShaderGen.cpp | 3 ++- Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp | 9 ++++++--- Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp | 6 ++++-- .../Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp | 3 ++- Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp | 6 ++++-- .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 3 ++- 19 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index b8e8d9c17c..dd1abe6ae9 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -25,6 +25,7 @@ #include #include "Common.h" +#include "StringUtil.h" // User directory indices for GetUserPath enum { @@ -226,4 +227,15 @@ private: } // namespace +// To deal with Windows being dumb at unicode: +template +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, openmode); +#endif +} + #endif diff --git a/Source/Core/Common/Src/IniFile.cpp b/Source/Core/Common/Src/IniFile.cpp index acad498106..da44855941 100644 --- a/Source/Core/Common/Src/IniFile.cpp +++ b/Source/Core/Common/Src/IniFile.cpp @@ -25,6 +25,7 @@ #include #include +#include "FileUtil.h" #include "StringUtil.h" #include "IniFile.h" @@ -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; @@ -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()) { diff --git a/Source/Core/Common/Src/LinearDiskCache.h b/Source/Core/Common/Src/LinearDiskCache.h index 9755c996bd..42b3d9ff15 100644 --- a/Source/Core/Common/Src/LinearDiskCache.h +++ b/Source/Core/Common/Src/LinearDiskCache.h @@ -74,7 +74,7 @@ public: 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(); diff --git a/Source/Core/Common/Src/LogManager.cpp b/Source/Core/Common/Src/LogManager.cpp index 3beae08c15..9b0ed43333 100644 --- a/Source/Core/Common/Src/LogManager.cpp +++ b/Source/Core/Common/Src/LogManager.cpp @@ -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); } diff --git a/Source/Core/Common/Src/NandPaths.cpp b/Source/Core/Common/Src/NandPaths.cpp index cec79414a7..eb0673afe0 100644 --- a/Source/Core/Common/Src/NandPaths.cpp +++ b/Source/Core/Common/Src/NandPaths.cpp @@ -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"; @@ -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; diff --git a/Source/Core/Core/Src/DSP/assemble.cpp b/Source/Core/Core/Src/DSP/assemble.cpp index dd394ab82c..248b0d8ba8 100644 --- a/Source/Core/Core/Src/DSP/assemble.cpp +++ b/Source/Core/Core/Src/DSP/assemble.cpp @@ -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()) { diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp index 5c2a28b57a..5710fd4f25 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp @@ -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(); } diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp index ba01239bf2..c743c80294 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp @@ -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); diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index 362e617696..fad0380eca 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -285,7 +285,8 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event) if (!path.IsEmpty()) { - std::ifstream f(WxStrToStr(path).c_str()); + std::ifstream f; + OpenFStream(f, WxStrToStr(path), std::ios_base::in); std::string line; while (std::getline(f, line)) diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 6434c8cd54..a194345585 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -137,7 +137,8 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW else { // Will fail out if GameConfig folder doesn't exist - std::ofstream f(GameIniFile.c_str()); + std::ofstream f; + OpenFStream(f, GameIniFile, std::ios_base::out); if (f) { f << "# " << OpenISO->GetUniqueID() << " - " << OpenISO->GetName() << '\n' diff --git a/Source/Core/VideoCommon/Src/ImageWrite.cpp b/Source/Core/VideoCommon/Src/ImageWrite.cpp index 23b0e73427..482b4dad25 100644 --- a/Source/Core/VideoCommon/Src/ImageWrite.cpp +++ b/Source/Core/VideoCommon/Src/ImageWrite.cpp @@ -69,7 +69,8 @@ bool SaveTGA(const char* filename, int width, int height, void* pdata) bool SaveData(const char* filename, const char* data) { - std::ofstream f(filename, std::ios::binary); + std::ofstream f; + OpenFStream(f, filename, std::ios::binary); f << data; return true; diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 448501aad0..6793862ef9 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -252,7 +252,8 @@ void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std:: static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%spsuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << msg; file << "\n\nOld shader code:\n" << old_code; file << "\n\nNew shader code:\n" << new_code; diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp index cd5a01c6b3..6d5d122704 100644 --- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp @@ -277,10 +277,12 @@ void VertexManager::Flush() // save the shaders char strfile[255]; sprintf(strfile, "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId); - std::ofstream fps(strfile); + std::ofstream fps; + OpenFStream(fps, strfile, std::ios_base::out); fps << ps->strprog.c_str(); sprintf(strfile, "%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId); - std::ofstream fvs(strfile); + std::ofstream fvs; + OpenFStream(fvs, strfile, std::ios_base::out); fvs << vs->strprog.c_str(); } diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index cad117c2c8..2ca6f67077 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -114,7 +114,8 @@ void ValidateVertexShaderIDs(API_TYPE api, VERTEXSHADERUIDSAFE old_id, const std static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%svsuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << msg; file << "\n\nOld shader code:\n" << old_code; file << "\n\nNew shader code:\n" << new_code; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp index 41e5423990..c688228945 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DShader.cpp @@ -64,7 +64,8 @@ bool CompileVertexShader(const char* code, unsigned int len, D3DBlob** blob) static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << code; file.close(); @@ -121,7 +122,8 @@ bool CompileGeometryShader(const char* code, unsigned int len, D3DBlob** blob, static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_gs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << code; file.close(); @@ -180,7 +182,8 @@ bool CompilePixelShader(const char* code, unsigned int len, D3DBlob** blob, static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << code; file.close(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp index 9c17c3df8c..c7c4cf266a 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DShader.cpp @@ -50,7 +50,8 @@ bool CompileVertexShader(const char *code, int len, u8 **bytecode, int *bytecode static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << code; file.close(); @@ -105,7 +106,8 @@ bool CompilePixelShader(const char *code, int len, u8 **bytecode, int *bytecodel static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << code; file.close(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 61e41008b3..572c7f19c7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -264,7 +264,8 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_ps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << pstrprogram; file.close(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index 6ea10fc077..a6da4d6fa4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -249,10 +249,12 @@ void VertexManager::vFlush() // save the shaders char strfile[255]; sprintf(strfile, "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId); - std::ofstream fps(strfile); + std::ofstream fps; + OpenFStream(fps, strfile, std::ios_base::out); fps << ps->strprog.c_str(); sprintf(strfile, "%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId); - std::ofstream fvs(strfile); + std::ofstream fvs; + OpenFStream(fvs, strfile, std::ios_base::out); fvs << vs->strprog.c_str(); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index dbbb7ee29b..7d003b8363 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -144,7 +144,8 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr static int num_failures = 0; char szTemp[MAX_PATH]; sprintf(szTemp, "%sbad_vs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++); - std::ofstream file(szTemp); + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); file << pstrprogram; file.close(); From b0630790c1c195ba7654c140d6c6baa4dcddd346 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 28 Feb 2013 19:42:29 -0600 Subject: [PATCH 12/26] It's 2013! Why can't I use C++11 yet!? --- Source/Core/Common/Src/FileUtil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index dd1abe6ae9..2747c50cf4 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -234,7 +234,7 @@ void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmod #ifdef _WIN32 fstream.open(UTF8ToTStr(filename).c_str(), openmode); #else - fstream.open(filename, openmode); + fstream.open(filename.c_str(), openmode); #endif } From e079d2491282f334f0d87dd16801550efcf8d4d1 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Fri, 1 Mar 2013 19:33:17 -0600 Subject: [PATCH 13/26] Kill wstring version of game description. --- Source/Core/DiscIO/Src/BannerLoader.cpp | 126 -------------------- Source/Core/DiscIO/Src/BannerLoader.h | 5 +- Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 120 ++++++++++++++++--- Source/Core/DiscIO/Src/BannerLoaderWii.h | 4 +- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 22 ++-- Source/Core/DolphinWX/Src/ISOFile.cpp | 9 +- Source/Core/DolphinWX/Src/ISOFile.h | 4 +- Source/Core/DolphinWX/Src/ISOProperties.cpp | 6 +- 8 files changed, 120 insertions(+), 176 deletions(-) diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index 2350896c9c..2c28401c93 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -22,25 +22,6 @@ #include "VolumeCreator.h" #include "FileUtil.h" -// HyperIris: dunno if this suitable, may be need move. -#ifdef _WIN32 -#include -#else -#include -#ifndef ANDROID -#include -#endif -#include -#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) @@ -96,113 +77,6 @@ void IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* _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)) diff --git a/Source/Core/DiscIO/Src/BannerLoader.h b/Source/Core/DiscIO/Src/BannerLoader.h index 1fe48dd364..ef2e0e64b9 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.h +++ b/Source/Core/DiscIO/Src/BannerLoader.h @@ -43,14 +43,11 @@ class IBannerLoader 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) { diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index b23dc4d91a..d8d8076721 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include +#include #include "Common.h" #include "ColorUtil.h" @@ -24,6 +25,25 @@ #include "FileUtil.h" #include "FileHandlerARC.h" +// HyperIris: dunno if this suitable, may be need move. +#ifdef _WIN32 +#include +#else +#include +#ifndef ANDROID +#include +#endif +#include +#endif + +#ifndef ICONV_CONST +#if defined __FreeBSD__ || __NetBSD__ +#define ICONV_CONST const +#else +#define ICONV_CONST +#endif +#endif + namespace DiscIO { @@ -152,16 +172,8 @@ bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::stri { // 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; + // TODO: trim NULLs + ret = CopyBeUnicodeToString(s, pBanner->m_Comment[index], COMMENT_SIZE); } return ret; @@ -208,11 +220,6 @@ bool CBannerLoaderWii::GetDescription(std::string* _rDescription) return GetStringFromComments(DESC_IDX, *_rDescription); } -bool CBannerLoaderWii::GetDescription(std::wstring& _rDescription) -{ - return GetStringFromComments(DESC_IDX, _rDescription); -} - void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) { for (int y = 0; y < height; y += 4) @@ -231,4 +238,87 @@ void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) } } +bool CBannerLoaderWii::CopyBeUnicodeToString( std::string& _rDestination, const u16* _src, int length ) +{ + bool returnCode = false; +#ifdef _WIN32 + if (_src) + { + std::wstring src; + src.resize(length); + std::transform(_src, _src + length, &src[0], (u16(&)(u16))Common::swap16); + + _rDestination = UTF16ToUTF8(src); + returnCode = true; + } +#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; +} + } // namespace diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.h b/Source/Core/DiscIO/Src/BannerLoaderWii.h index 83733cf5ed..d7150d7009 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.h +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.h @@ -43,8 +43,6 @@ class CBannerLoaderWii virtual bool GetDescription(std::string* _rDescription); - bool GetDescription(std::wstring& _rDescription); - private: enum @@ -82,6 +80,8 @@ class CBannerLoaderWii bool GetStringFromComments(const CommentIndex index, std::string& s); bool GetStringFromComments(const CommentIndex index, std::wstring& s); + + bool CopyBeUnicodeToString(std::string& _rDestination, const u16* _src, int length); }; } // namespace diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index cab4c8125b..c24f0509ba 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -456,16 +456,9 @@ void CGameListCtrl::InsertItemInReportView(long _Index) SetItemColumnImage(_Index, COLUMN_BANNER, ImageIndex); std::wstring wstring_name; - const std::wstring& wstring_description = rISOFile.GetDescription(); - std::string company; wxString name; - wxString description; - // We show the company string on Gamecube only - // On Wii we show the description instead as the company string is empty - if (rISOFile.GetPlatform() == GameListItem::GAMECUBE_DISC) - company = rISOFile.GetCompany().c_str(); int SelectedLanguage = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; switch (rISOFile.GetCountry()) { @@ -475,11 +468,10 @@ void CGameListCtrl::InsertItemInReportView(long _Index) rISOFile.GetName(wstring_name, -1); name = wxString(rISOFile.GetName(0).c_str(), SJISConv); m_gameList.append(StringFromFormat("%s (J)\n", (const char *)name.c_str())); - description = wxString(company.size() ? company.c_str() : - rISOFile.GetDescription(0).c_str(), SJISConv); } break; case DiscIO::IVolume::COUNTRY_USA: + // Is this sane? SelectedLanguage = 0; default: { @@ -490,19 +482,21 @@ void CGameListCtrl::InsertItemInReportView(long _Index) m_gameList.append(StringFromFormat("%s (%c)\n", rISOFile.GetName(SelectedLanguage).c_str(), (rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E')); - description = wxString(company.size() ? company.c_str() : - rISOFile.GetDescription(SelectedLanguage).c_str(), WindowsCP1252); + } break; } if (wstring_name.length()) name = wstring_name.c_str(); - if (wstring_description.length()) - description = wstring_description.c_str(); SetItem(_Index, COLUMN_TITLE, name, -1); - SetItem(_Index, COLUMN_NOTES, description, -1); + + // We show the company string on Gamecube only + // On Wii we show the description instead as the company string is empty + std::string const notes = (rISOFile.GetPlatform() == GameListItem::GAMECUBE_DISC) ? + rISOFile.GetCompany() : rISOFile.GetDescription(SelectedLanguage); + SetItem(_Index, COLUMN_NOTES, StrToWxStr(notes), -1); // Emulation state SetItemColumnImage(_Index, COLUMN_EMULATION_STATE, m_EmuStateImageIndex[rISOFile.GetEmuState()]); diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index 639190fa0e..918a72b0bf 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -37,7 +37,7 @@ #include "ChunkFile.h" #include "ConfigManager.h" -#define CACHE_REVISION 0x10F +#define CACHE_REVISION 0x110 #define DVD_BANNER_WIDTH 96 #define DVD_BANNER_HEIGHT 32 @@ -109,7 +109,6 @@ GameListItem::GameListItem(const std::string& _rFileName) pBannerLoader->GetName(m_wNames); pBannerLoader->GetName(m_Name); pBannerLoader->GetCompany(m_Company); - pBannerLoader->GetDescription(m_wDescription); pBannerLoader->GetDescription(m_Description); if (pBannerLoader->GetBanner(g_ImageTemp)) @@ -235,7 +234,6 @@ void GameListItem::DoState(PointerWrap &p) p.Do(m_Company); p.Do(m_Description[0]); p.Do(m_Description[1]); p.Do(m_Description[2]); p.Do(m_Description[3]); p.Do(m_Description[4]); p.Do(m_Description[5]); - p.Do(m_wDescription); p.Do(m_UniqueID); p.Do(m_FileSize); p.Do(m_VolumeSize); @@ -273,11 +271,6 @@ const std::string& GameListItem::GetDescription(int index) const return m_Description[0]; } -const std::wstring& GameListItem::GetDescription() const -{ - return m_wDescription; -} - const std::string& GameListItem::GetName(int index) const { if ((index >=0) && (index < 6)) diff --git a/Source/Core/DolphinWX/Src/ISOFile.h b/Source/Core/DolphinWX/Src/ISOFile.h index e58dcf7713..1f3ecaa261 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.h +++ b/Source/Core/DolphinWX/Src/ISOFile.h @@ -37,8 +37,7 @@ public: const std::string& GetName(int index) const; bool GetName(std::wstring& wName, int index=0) const; const std::string& GetCompany() const {return m_Company;} - const std::string& GetDescription(int index) const; - const std::wstring& GetDescription() const; + const std::string& GetDescription(int index = 0) const; const std::string& GetUniqueID() const {return m_UniqueID;} const std::string GetWiiFSPath() const; DiscIO::IVolume::ECountry GetCountry() const {return m_Country;} @@ -69,7 +68,6 @@ private: std::vector m_wNames; std::string m_Company; std::string m_Description[6]; - std::wstring m_wDescription; std::string m_UniqueID; std::string m_issues; diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index a194345585..21d451a1ac 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -1339,8 +1339,7 @@ void CISOProperties::ChangeBannerDetails(int lang) else shortName = wxString(OpenGameListItem->GetName(0).c_str(), SJISConv); - if ((comment = OpenGameListItem->GetDescription().c_str()).size() == 0) - comment = wxString(OpenGameListItem->GetDescription(0).c_str(), SJISConv); + comment = StrToWxStr(OpenGameListItem->GetDescription()); maker = wxString(OpenGameListItem->GetCompany().c_str(), SJISConv); break; case DiscIO::IVolume::COUNTRY_USA: @@ -1352,8 +1351,7 @@ void CISOProperties::ChangeBannerDetails(int lang) shortName = wname.c_str(); else shortName = wxString(OpenGameListItem->GetName(lang).c_str(), WindowsCP1252); - if ((comment = OpenGameListItem->GetDescription().c_str()).size() == 0) - comment = wxString(OpenGameListItem->GetDescription(lang).c_str(), WindowsCP1252); + comment = StrToWxStr(OpenGameListItem->GetDescription(lang)); maker = wxString(OpenGameListItem->GetCompany().c_str(), WindowsCP1252); } break; From 6c8adf6130b32a0ffc113f4ce30f70b9d5994f10 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 2 Mar 2013 19:46:55 -0600 Subject: [PATCH 14/26] Eliminate the wstring game name. Some cleanup throughout related code. (try to make logic in ISOFile understandable by a human) Encode strings in UTF-8 rather than somehow trying to determine the encoding in the GUI code. Non-windows OSes temporarily broken. --- Source/Core/Common/Src/StringUtil.cpp | 30 +++- Source/Core/Common/Src/StringUtil.h | 4 +- Source/Core/DiscIO/Src/BannerLoader.cpp | 52 ------- Source/Core/DiscIO/Src/BannerLoader.h | 15 +- Source/Core/DiscIO/Src/BannerLoaderGC.cpp | 138 ++++++++----------- Source/Core/DiscIO/Src/BannerLoaderGC.h | 30 ++-- Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 25 ++-- Source/Core/DiscIO/Src/BannerLoaderWii.h | 10 +- Source/Core/DiscIO/Src/Volume.h | 4 +- Source/Core/DiscIO/Src/VolumeCommon.cpp | 10 +- Source/Core/DiscIO/Src/VolumeDirectory.cpp | 5 +- Source/Core/DiscIO/Src/VolumeDirectory.h | 2 +- Source/Core/DiscIO/Src/VolumeGC.cpp | 13 +- Source/Core/DiscIO/Src/VolumeGC.h | 2 +- Source/Core/DiscIO/Src/VolumeWad.cpp | 48 ++----- Source/Core/DiscIO/Src/VolumeWad.h | 3 +- Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp | 18 +-- Source/Core/DiscIO/Src/VolumeWiiCrypted.h | 2 +- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 26 ++-- Source/Core/DolphinWX/Src/ISOFile.cpp | 144 +++++++------------- Source/Core/DolphinWX/Src/ISOFile.h | 23 ++-- Source/Core/DolphinWX/Src/ISOProperties.cpp | 50 ++----- 22 files changed, 243 insertions(+), 411 deletions(-) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 38ac107ec1..aab0f3bd58 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -395,17 +395,41 @@ std::string UTF16ToUTF8(const std::wstring& input) return output; } -std::wstring UTF8ToUTF16(const std::string& input) +std::wstring CPToUTF16(u32 code_page, const std::string& input) { - auto const size = MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), nullptr, 0); + auto const size = MultiByteToWideChar(code_page, 0, input.data(), input.size(), nullptr, 0); std::wstring output; output.resize(size); - if (size != MultiByteToWideChar(CP_UTF8, 0, input.data(), input.size(), &output[0], output.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)); +} + +#else + +std::string UTF16ToUTF8(const std::wstring& input) +{ + // TODO: implement + return std::string(); +} + +std::string SHIFTJISToUTF8(const std::string& input) +{ + // TODO: implement + return std::string(); +} + #endif diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index 5177bc8ed8..ce5751f80b 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -97,9 +97,11 @@ 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 SHIFTJISToUTF8(const std::string& str); +std::string UTF16ToUTF8(const std::wstring& str); + #ifdef _WIN32 -std::string UTF16ToUTF8(const std::wstring& str); std::wstring UTF8ToUTF16(const std::string& str); #ifdef _UNICODE diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index 2c28401c93..7e641aa85b 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -24,58 +24,6 @@ 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; -} IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume) { diff --git a/Source/Core/DiscIO/Src/BannerLoader.h b/Source/Core/DiscIO/Src/BannerLoader.h index ef2e0e64b9..92bb874979 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.h +++ b/Source/Core/DiscIO/Src/BannerLoader.h @@ -18,6 +18,9 @@ #ifndef _BANNER_LOADER_H_ #define _BANNER_LOADER_H_ +#include +#include + #include "Filesystem.h" namespace DiscIO @@ -38,15 +41,9 @@ class IBannerLoader virtual bool GetBanner(u32* _pBannerImage) = 0; - virtual bool GetName(std::string* _rName) = 0; - virtual bool GetName(std::vector& _rNames) {return false;}; - virtual bool GetCompany(std::string& _rCompany) = 0; - - virtual bool GetDescription(std::string* _rDescription) = 0; - - protected: - - void CopyToStringAndCheck(std::string& _rDestination, const char* _src); + virtual std::vector GetNames() = 0; + virtual std::string GetCompany() = 0; + virtual std::vector GetDescriptions() = 0; private: u16 swap16(u16 data) diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp index bf9f634ff8..bf087cbfb6 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp @@ -29,7 +29,7 @@ CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem) { // 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) @@ -62,7 +62,6 @@ bool CBannerLoaderGC::IsValid() return m_IsValid; } - bool CBannerLoaderGC::GetBanner(u32* _pBannerImage) { if (!IsValid()) @@ -70,132 +69,111 @@ bool CBannerLoaderGC::GetBanner(u32* _pBannerImage) 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 CBannerLoaderGC::GetNames() { - bool returnCode = false; + std::vector 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; - - 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); - } - - returnCode = true; - - } + name_count = 6; break; + default: break; } + + auto const banner = reinterpret_cast(m_pBannerFile); + + for (int 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)); + } + } - 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 CBannerLoaderGC::GetDescriptions() { - bool returnCode = false; + std::vector 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(m_pBannerFile); + + for (int i = 0; i != desc_count; ++i) + { + auto& data = banner->comment[i].comment; + descriptions.push_back(GetDecodedString(data)); + } + + return descriptions; } @@ -223,13 +201,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 diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.h b/Source/Core/DiscIO/Src/BannerLoaderGC.h index 0527c721c1..b4903561e4 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.h +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.h @@ -32,9 +32,10 @@ class 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 GetNames(); + virtual std::string GetCompany(); + virtual std::vector GetDescriptions(); private: enum @@ -60,24 +61,25 @@ class CBannerLoaderGC char comment[128]; // Game description shown in IPL game start screen in two lines. }; - // "opening.bnr" file format for JP/US console - struct DVDBanner - { - u32 id; // 'BNR1' - u32 padding[7]; - u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image - DVDBannerComment comment; - }; - // "opening.bnr" file format for EU console - struct DVDBanner2 + struct DVDBanner { 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 + DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type) }; + static const u32 BNR1_SIZE = sizeof(DVDBanner) - sizeof(DVDBannerComment) * 5; + static const u32 BNR2_SIZE = sizeof(DVDBanner); + + template + std::string GetDecodedString(const char (&data)[N]) + { + // Can I always assume SHIFT-JIS? + return SHIFTJISToUTF8(std::string(data, strnlen(data, sizeof(data)))); + } + u8* m_pBannerFile; bool m_IsValid; BANNER_TYPE m_BNRType; diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index d8d8076721..b94e299f04 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -196,28 +196,27 @@ bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::wstr return false; } -bool CBannerLoaderWii::GetName(std::string* _rName) +std::vector CBannerLoaderWii::GetNames() { - return GetStringFromComments(NAME_IDX, *_rName); -} + std::vector ret(1); + + if (!GetStringFromComments(NAME_IDX, ret[0])) + ret.clear(); -bool CBannerLoaderWii::GetName(std::vector& _rNames) -{ - std::wstring temp; - bool ret = GetStringFromComments(NAME_IDX, temp); - _rNames.push_back(temp); return ret; } -bool CBannerLoaderWii::GetCompany(std::string& _rCompany) +std::string CBannerLoaderWii::GetCompany() { - _rCompany = "N/A"; - return true; + return ""; } -bool CBannerLoaderWii::GetDescription(std::string* _rDescription) +std::vector CBannerLoaderWii::GetDescriptions() { - return GetStringFromComments(DESC_IDX, *_rDescription); + std::vector result(1); + if (!GetStringFromComments(DESC_IDX, result[0])) + result.clear(); + return result; } void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.h b/Source/Core/DiscIO/Src/BannerLoaderWii.h index d7150d7009..60d317155b 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.h +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.h @@ -35,13 +35,9 @@ class CBannerLoaderWii virtual bool GetBanner(u32* _pBannerImage); - virtual bool GetName(std::string* _rName); - - bool GetName(std::vector& _rNames); - - virtual bool GetCompany(std::string& _rCompany); - - virtual bool GetDescription(std::string* _rDescription); + virtual std::vector GetNames(); + virtual std::string GetCompany(); + virtual std::vector GetDescriptions(); private: diff --git a/Source/Core/DiscIO/Src/Volume.h b/Source/Core/DiscIO/Src/Volume.h index 557c71c31f..4743cfce89 100644 --- a/Source/Core/DiscIO/Src/Volume.h +++ b/Source/Core/DiscIO/Src/Volume.h @@ -37,8 +37,8 @@ public: 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& _rwNames) const { return false; } + virtual std::string GetName() const; + virtual std::vector GetNames() const = 0; virtual u32 GetFSTSize() const = 0; virtual std::string GetApploaderDate() const = 0; virtual bool SupportsIntegrityCheck() const { return false; } diff --git a/Source/Core/DiscIO/Src/VolumeCommon.cpp b/Source/Core/DiscIO/Src/VolumeCommon.cpp index 415af2725a..4ab433680d 100644 --- a/Source/Core/DiscIO/Src/VolumeCommon.cpp +++ b/Source/Core/DiscIO/Src/VolumeCommon.cpp @@ -111,5 +111,13 @@ u8 GetSysMenuRegion(u16 _TitleVersion) } } -}; +std::string IVolume::GetName() const +{ + auto names = GetNames(); + if (names.empty()) + return ""; + else + return names[0]; +} +} diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.cpp b/Source/Core/DiscIO/Src/VolumeDirectory.cpp index dc76e2e641..be7cdeb565 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/Src/VolumeDirectory.cpp @@ -207,11 +207,10 @@ std::string CVolumeDirectory::GetMakerID() const return "VOID"; } -std::string CVolumeDirectory::GetName() const +std::vector CVolumeDirectory::GetNames() const { _dbg_assert_(DVDINTERFACE, m_diskHeader); - std::string name = (char*)(m_diskHeader + 0x20); - return name; + return std::vector(1, (char*)(m_diskHeader + 0x20)); } void CVolumeDirectory::SetName(std::string _Name) diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.h b/Source/Core/DiscIO/Src/VolumeDirectory.h index 0547be3b8a..880a6eebc1 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.h +++ b/Source/Core/DiscIO/Src/VolumeDirectory.h @@ -50,7 +50,7 @@ public: std::string GetMakerID() const; - std::string GetName() const; + std::vector GetNames() const; void SetName(std::string); u32 GetFSTSize() const; diff --git a/Source/Core/DiscIO/Src/VolumeGC.cpp b/Source/Core/DiscIO/Src/VolumeGC.cpp index 09e2c5eaa9..6e9579571a 100644 --- a/Source/Core/DiscIO/Src/VolumeGC.cpp +++ b/Source/Core/DiscIO/Src/VolumeGC.cpp @@ -91,16 +91,15 @@ std::string CVolumeGC::GetMakerID() const return makerID; } -std::string CVolumeGC::GetName() const +std::vector CVolumeGC::GetNames() const { - if (m_pReader == NULL) - return ""; + std::vector names; - char name[128]; - if (!Read(0x20, 0x60, (u8*)&name)) - return ""; + char name[128] = {}; + if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name)) + names.push_back(name); - return name; + return names; } u32 CVolumeGC::GetFSTSize() const diff --git a/Source/Core/DiscIO/Src/VolumeGC.h b/Source/Core/DiscIO/Src/VolumeGC.h index 4221df9493..dab1ad7a9d 100644 --- a/Source/Core/DiscIO/Src/VolumeGC.h +++ b/Source/Core/DiscIO/Src/VolumeGC.h @@ -34,7 +34,7 @@ public: bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const; std::string GetUniqueID() const; std::string GetMakerID() const; - std::string GetName() const; + std::vector GetNames() const; u32 GetFSTSize() const; std::string GetApploaderDate() const; ECountry GetCountry() const; diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp index 2f9f0ef961..72788f1017 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.cpp +++ b/Source/Core/DiscIO/Src/VolumeWad.cpp @@ -107,13 +107,15 @@ bool CVolumeWAD::GetTitleID(u8* _pBuffer) const return true; } -bool CVolumeWAD::GetWName(std::vector& _rwNames) const +std::vector CVolumeWAD::GetNames() const { - u32 footer_size; + std::vector names; + return names; + u32 footer_size; if (!Read(0x1C, 4, (u8*)&footer_size)) { - return false; + return names; } //Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean @@ -126,7 +128,7 @@ bool CVolumeWAD::GetWName(std::vector& _rwNames) const if (!Read(0x9C + (i*84) + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1 || !temp[0]) { - _rwNames.push_back(L""); + names.push_back(""); continue; } for (int j = 0; j < 42; ++j) @@ -141,44 +143,10 @@ bool CVolumeWAD::GetWName(std::vector& _rwNames) const out_temp.push_back(t); } - _rwNames.push_back(out_temp); + names.push_back(UTF16ToUTF8(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(' '); - } - 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 diff --git a/Source/Core/DiscIO/Src/VolumeWad.h b/Source/Core/DiscIO/Src/VolumeWad.h index 956844acd1..afc16766a2 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.h +++ b/Source/Core/DiscIO/Src/VolumeWad.h @@ -38,8 +38,7 @@ public: bool GetTitleID(u8* _pBuffer) const; std::string GetUniqueID() const; std::string GetMakerID() const; - std::string GetName() const; - bool GetWName(std::vector& _rwNames) const; + std::vector GetNames() const; u32 GetFSTSize() const { return 0; } std::string GetApploaderDate() const { return "0"; } ECountry GetCountry() const; diff --git a/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp index ca010b5ae4..f375b9e66d 100644 --- a/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp @@ -168,21 +168,17 @@ std::string CVolumeWiiCrypted::GetMakerID() const return makerID; } -std::string CVolumeWiiCrypted::GetName() const +std::vector CVolumeWiiCrypted::GetNames() const { - if (m_pReader == NULL) + std::vector names; + + char name[0xFF] = {}; + if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name)) { - return std::string(); + names.push_back(name); } - char name[0xFF]; - - if (!Read(0x20, 0x60, (u8*)&name)) - { - return std::string(); - } - - return name; + return names; } u32 CVolumeWiiCrypted::GetFSTSize() const diff --git a/Source/Core/DiscIO/Src/VolumeWiiCrypted.h b/Source/Core/DiscIO/Src/VolumeWiiCrypted.h index 5010e46bbd..56c2a8a363 100644 --- a/Source/Core/DiscIO/Src/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/Src/VolumeWiiCrypted.h @@ -37,7 +37,7 @@ public: void GetTMD(u8* _pBuffer, u32* _sz) const; std::string GetUniqueID() const; std::string GetMakerID() const; - std::string GetName() const; + std::vector GetNames() const; u32 GetFSTSize() const; std::string GetApploaderDate() const; ECountry GetCountry() const; diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index c24f0509ba..6a6df49ee5 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -454,10 +454,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index) // Set the game's banner in the second column SetItemColumnImage(_Index, COLUMN_BANNER, ImageIndex); - - std::wstring wstring_name; - wxString name; + std::string name; int SelectedLanguage = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; switch (rISOFile.GetCountry()) @@ -465,9 +463,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index) case DiscIO::IVolume::COUNTRY_TAIWAN: case DiscIO::IVolume::COUNTRY_JAPAN: { - rISOFile.GetName(wstring_name, -1); - name = wxString(rISOFile.GetName(0).c_str(), SJISConv); - m_gameList.append(StringFromFormat("%s (J)\n", (const char *)name.c_str())); + name = rISOFile.GetName(-1); + m_gameList.append(StringFromFormat("%s (J)\n", name.c_str())); } break; case DiscIO::IVolume::COUNTRY_USA: @@ -475,22 +472,15 @@ void CGameListCtrl::InsertItemInReportView(long _Index) SelectedLanguage = 0; default: { - wxCSConv WindowsCP1252(wxFontMapper::GetEncodingName(wxFONTENCODING_CP1252)); - rISOFile.GetName(wstring_name, SelectedLanguage); - - name = wxString(rISOFile.GetName(SelectedLanguage).c_str(), WindowsCP1252); - m_gameList.append(StringFromFormat("%s (%c)\n", - rISOFile.GetName(SelectedLanguage).c_str(), - (rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E')); + name = rISOFile.GetName(SelectedLanguage); + m_gameList.append(StringFromFormat("%s (%c)\n", name.c_str(), + (rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E')); } break; } - - if (wstring_name.length()) - name = wstring_name.c_str(); - - SetItem(_Index, COLUMN_TITLE, name, -1); + + SetItem(_Index, COLUMN_TITLE, StrToWxStr(name), -1); // We show the company string on Gamecube only // On Wii we show the description instead as the company string is empty diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index 918a72b0bf..ec8280a726 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -37,7 +37,7 @@ #include "ChunkFile.h" #include "ConfigManager.h" -#define CACHE_REVISION 0x110 +#define CACHE_REVISION 0x112 #define DVD_BANNER_WIDTH 96 #define DVD_BANNER_HEIGHT 32 @@ -66,26 +66,10 @@ GameListItem::GameListItem(const std::string& _rFileName) else { m_Platform = WII_WAD; - pVolume->GetWName(m_wNames); } - m_Company = "N/A"; + m_volume_names = pVolume->GetNames(); - - m_Name[0] = pVolume->GetName(); - - if(m_Name[0] == "") // Couldn't find the name in the WAD... - { - std::string FileName; - SplitPath(m_FileName, NULL, &FileName, NULL); - m_Name[0] = FileName; // Then just display the filename... Better than something like "No Name" - } - - for (int i = 0; i < 6; i++) - { - m_Name[i] = m_Name[0]; - m_Description[i] = "No Description"; - } m_Country = pVolume->GetCountry(); m_FileSize = File::GetSize(_rFileName); m_VolumeSize = pVolume->GetSize(); @@ -105,11 +89,9 @@ GameListItem::GameListItem(const std::string& _rFileName) { if (pBannerLoader->IsValid()) { - m_wNames.clear(); - pBannerLoader->GetName(m_wNames); - pBannerLoader->GetName(m_Name); - pBannerLoader->GetCompany(m_Company); - pBannerLoader->GetDescription(m_Description); + m_names = pBannerLoader->GetNames(); + m_company = pBannerLoader->GetCompany(); + m_descriptions = pBannerLoader->GetDescriptions(); if (pBannerLoader->GetBanner(g_ImageTemp)) { @@ -129,25 +111,6 @@ GameListItem::GameListItem(const std::string& _rFileName) delete pFileSystem; } - std::vector::iterator i, end = m_wNames.end(); - std::wstring wFileName; - for (i = m_wNames.begin(); i != end; ++i) - { - if (*i == L"") - { - if (!wFileName.length()) - { - std::string FileName; - SplitPath(m_FileName, NULL, &FileName, NULL); - int length = FileName.length(); - wFileName.reserve(length+1); - for (int j = 0; j < length; ++j) - wFileName.push_back(FileName[j]); - wFileName.push_back(0); - } - *i = wFileName; - } - } delete pVolume; @@ -208,32 +171,10 @@ void GameListItem::SaveToCache() void GameListItem::DoState(PointerWrap &p) { - p.Do(m_Name[0]); p.Do(m_Name[1]); p.Do(m_Name[2]); - p.Do(m_Name[3]); p.Do(m_Name[4]); p.Do(m_Name[5]); - - int wNamesSize = m_wNames.size(); - p.Do(wNamesSize); - - if (p.mode == p.MODE_READ) - { - for (int i = 0; i < wNamesSize; ++i) - { - std::wstring temp; - p.Do(temp); - m_wNames.push_back(temp); - } - } - else - { - for (int i = 0; i < wNamesSize; ++i) - { - p.Do(m_wNames[i]); - } - } - - p.Do(m_Company); - p.Do(m_Description[0]); p.Do(m_Description[1]); p.Do(m_Description[2]); - p.Do(m_Description[3]); p.Do(m_Description[4]); p.Do(m_Description[5]); + p.Do(m_volume_names); + p.Do(m_company); + p.Do(m_names); + p.Do(m_descriptions); p.Do(m_UniqueID); p.Do(m_FileSize); p.Do(m_VolumeSize); @@ -262,44 +203,51 @@ std::string GameListItem::CreateCacheFilename() return fullname; } -const std::string& GameListItem::GetDescription(int index) const +std::string GameListItem::GetCompany() const { - if ((index >=0) && (index < 6)) - { - return m_Description[index]; - } - return m_Description[0]; + if (m_company.empty()) + return "N/A"; + else + return m_company; } -const std::string& GameListItem::GetName(int index) const +// (-1 = Japanese, 0 = English, etc) +std::string GameListItem::GetDescription(int _index) const { - if ((index >=0) && (index < 6)) - { - return m_Name[index]; - } - return m_Name[0]; + const u32 index = _index + 1; + + if (index < m_descriptions.size()) + return m_descriptions[index]; + + if (!m_descriptions.empty()) + return m_descriptions[0]; + + return ""; } -bool GameListItem::GetName(std::wstring& wName, int index) const +// (-1 = Japanese, 0 = English, etc) +std::string GameListItem::GetName(int _index) const { - // This function will only succeed for wii discs with banners or WADs - // utilize the same array as for gc discs (-1= Japanese, 0 = English etc - index++; - if ((index >= 0) && (index < 10)) - { - if (m_wNames.size() > (size_t)index) - { - wName = m_wNames[index]; - return true; - } - } - if (m_wNames.size() > 0) - { - wName = m_wNames[0]; - return true; - } - return false; + u32 const index = _index + 1; + // banner name + if (index < m_names.size() && !m_names[index].empty()) + return m_names[index]; + + if (!m_names.empty() && !m_names[0].empty()) + return m_names[0]; + + // volume name + if (index < m_volume_names.size() && !m_volume_names[index].empty()) + return m_volume_names[index]; + + if (!m_volume_names.empty() && !m_volume_names[0].empty()) + return m_volume_names[0]; + + // No usable name, return filename (better than nothing) + std::string FileName; + SplitPath(m_FileName, NULL, &FileName, NULL); + return FileName; } const std::string GameListItem::GetWiiFSPath() const diff --git a/Source/Core/DolphinWX/Src/ISOFile.h b/Source/Core/DolphinWX/Src/ISOFile.h index 1f3ecaa261..ded392f56a 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.h +++ b/Source/Core/DolphinWX/Src/ISOFile.h @@ -18,6 +18,9 @@ #ifndef __ISOFILE_H_ #define __ISOFILE_H_ +#include +#include + #include "Volume.h" #include "VolumeCreator.h" @@ -34,10 +37,9 @@ public: bool IsValid() const {return m_Valid;} const std::string& GetFileName() const {return m_FileName;} - const std::string& GetName(int index) const; - bool GetName(std::wstring& wName, int index=0) const; - const std::string& GetCompany() const {return m_Company;} - const std::string& GetDescription(int index = 0) const; + std::string GetName(int index) const; + std::string GetCompany() const; + std::string GetDescription(int index = 0) const; const std::string& GetUniqueID() const {return m_UniqueID;} const std::string GetWiiFSPath() const; DiscIO::IVolume::ECountry GetCountry() const {return m_Country;} @@ -64,10 +66,15 @@ public: private: std::string m_FileName; - std::string m_Name[6]; - std::vector m_wNames; - std::string m_Company; - std::string m_Description[6]; + + // TODO: eliminate this and overwrite with names from banner when available? + std::vector m_volume_names; + + // Stuff from banner + std::string m_company; + std::vector m_names; + std::vector m_descriptions; + std::string m_UniqueID; std::string m_issues; diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 21d451a1ac..5993111698 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -158,15 +158,8 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW // Disk header and apploader - std::wstring wname; - wxString name; - if (OpenGameListItem->GetName(wname)) - name = wname.c_str(); - else - name = wxString(OpenISO->GetName().c_str(), wxConvUTF8); - m_Name->SetValue(name); - - m_GameID->SetValue(wxString(OpenISO->GetUniqueID().c_str(), wxConvUTF8)); + m_Name->SetValue(StrToWxStr(OpenISO->GetName())); + m_GameID->SetValue(StrToWxStr(OpenISO->GetUniqueID())); switch (OpenISO->GetCountry()) { case DiscIO::IVolume::COUNTRY_EUROPE: @@ -1308,54 +1301,29 @@ void CISOProperties::OnChangeBannerLang(wxCommandEvent& event) void CISOProperties::ChangeBannerDetails(int lang) { - std::wstring wname; + std::string name; wxString shortName, comment, maker; -#ifdef _WIN32 - wxCSConv SJISConv(*(wxCSConv*)wxConvCurrent); - static bool validCP932 = ::IsValidCodePage(932) != 0; - if (validCP932) - { - SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS)); - } - else - { - WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932"); - } -#else - // on linux the wrong string is returned from wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS) - // it returns CP-932, in order to use iconv we need to use CP932 - wxCSConv SJISConv(wxT("CP932")); -#endif switch (OpenGameListItem->GetCountry()) { case DiscIO::IVolume::COUNTRY_TAIWAN: case DiscIO::IVolume::COUNTRY_JAPAN: - - if (OpenGameListItem->GetName(wname, -1)) - shortName = wname.c_str(); - else - shortName = wxString(OpenGameListItem->GetName(0).c_str(), SJISConv); - + shortName = StrToWxStr(OpenGameListItem->GetName(-1)); comment = StrToWxStr(OpenGameListItem->GetDescription()); - maker = wxString(OpenGameListItem->GetCompany().c_str(), SJISConv); break; case DiscIO::IVolume::COUNTRY_USA: + // why? lang = 0; default: - { - wxCSConv WindowsCP1252(wxFontMapper::GetEncodingName(wxFONTENCODING_CP1252)); - if (OpenGameListItem->GetName(wname, lang)) - shortName = wname.c_str(); - else - shortName = wxString(OpenGameListItem->GetName(lang).c_str(), WindowsCP1252); + shortName = StrToWxStr(OpenGameListItem->GetName(lang)); comment = StrToWxStr(OpenGameListItem->GetDescription(lang)); - maker = wxString(OpenGameListItem->GetCompany().c_str(), WindowsCP1252); - } break; } + + maker = StrToWxStr(OpenGameListItem->GetCompany()); + // Updates the informations shown in the window m_ShortName->SetValue(shortName); m_Comment->SetValue(comment); From e183711d749fefd480ef8091acfd1230ae8c604e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 2 Mar 2013 20:34:53 -0600 Subject: [PATCH 15/26] wxString conversion cleanup. --- .../Src/Debugger/CodeWindowFunctions.cpp | 2 +- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 17 ----------------- Source/Core/DolphinWX/Src/ISOProperties.cpp | 16 ++++++++-------- Source/Core/DolphinWX/Src/MemcardManager.cpp | 10 +++++----- Source/Core/DolphinWX/Src/NetWindow.cpp | 2 +- 5 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index fad0380eca..ef4622d14f 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -209,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); } diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 6a6df49ee5..562d2234cd 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -423,23 +423,6 @@ void CGameListCtrl::InsertItemInReportView(long _Index) // company: 0x007030 int ImageIndex = -1; -#ifdef _WIN32 - wxCSConv SJISConv(*(wxCSConv*)wxConvCurrent); - static bool validCP932 = ::IsValidCodePage(932) != 0; - if (validCP932) - { - SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS)); - } - else - { - WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932"); - } -#else - // on linux the wrong string is returned from wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS) - // it returns CP-932, in order to use iconv we need to use CP932 - wxCSConv SJISConv(wxT("CP932")); -#endif - GameListItem& rISOFile = *m_ISOFiles[_Index]; m_gamePath.append(rISOFile.GetFileName() + '\n'); diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 5993111698..43657300cb 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -152,7 +152,7 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW LoadGameConfig(); else wxMessageBox(wxString::Format(_("Could not create %s"), - wxString::From8BitData(GameIniFile.c_str()).c_str()), + StrToWxStr(GameIniFile).c_str()), _("Error"), wxOK|wxICON_ERROR, this); } @@ -199,9 +199,9 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW m_Country->SetValue(_("UNKNOWN")); break; } - wxString temp = _T("0x") + wxString::From8BitData(OpenISO->GetMakerID().c_str()); + wxString temp = _T("0x") + StrToWxStr(OpenISO->GetMakerID()); m_MakerID->SetValue(temp); - m_Date->SetValue(wxString::From8BitData(OpenISO->GetApploaderDate().c_str())); + m_Date->SetValue(StrToWxStr(OpenISO->GetApploaderDate())); m_FST->SetValue(wxString::Format(wxT("%u"), OpenISO->GetFSTSize())); // Here we set all the info to be shown (be it SJIS or Ascii) + we set the window title @@ -266,12 +266,12 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, // check next index if (rFileInfo->IsDirectory()) { - wxTreeItemId item = m_Treectrl->AppendItem(parent, wxString::From8BitData(itemName), 1, 1); + wxTreeItemId item = m_Treectrl->AppendItem(parent, StrToWxStr(itemName), 1, 1); CurrentIndex = CreateDirectoryTree(item, fileInfos, CurrentIndex + 1, (size_t)rFileInfo->m_FileSize); } else { - m_Treectrl->AppendItem(parent, wxString::From8BitData(itemName), 2, 2); + m_Treectrl->AppendItem(parent, StrToWxStr(itemName), 2, 2); CurrentIndex++; } } @@ -1081,7 +1081,7 @@ bool CISOProperties::SaveGameConfig() void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) { - if (wxFileExists(wxString::From8BitData(GameIniFile.c_str()))) + if (File::Exists(GameIniFile)) { SaveGameConfig(); @@ -1102,7 +1102,7 @@ void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) } } wxString OpenCommand; - OpenCommand = filetype->GetOpenCommand(wxString::From8BitData(GameIniFile.c_str())); + OpenCommand = filetype->GetOpenCommand(StrToWxStr(GameIniFile)); if(OpenCommand.IsEmpty()) PanicAlertT("Couldn't find open command for extension 'ini'!"); else @@ -1275,7 +1275,7 @@ void CISOProperties::ActionReplayButtonClicked(wxCommandEvent& event) CARCodeAddEdit dlg(-1, this, 1, _("Add ActionReplay Code")); if (dlg.ShowModal() == wxID_OK) { - Cheats->Append(wxString::From8BitData(arCodes.back().name.c_str())); + Cheats->Append(StrToWxStr(arCodes.back().name)); Cheats->Check((unsigned int)(arCodes.size() - 1), arCodes.back().active); } } diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index d9fd4d3ae6..b9b26b6da8 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -214,7 +214,7 @@ void CMemcardManager::CreateGUIControls() sPages->Add(m_NextPage[slot], 0, wxEXPAND|wxALL, 1); m_MemcardPath[slot] = new wxFilePickerCtrl(this, ID_MEMCARDPATH_A + slot, - wxString::From8BitData(File::GetUserPath(D_GCUSER_IDX).c_str()), _("Choose a memory card:"), + StrToWxStr(File::GetUserPath(D_GCUSER_IDX)), _("Choose a memory card:"), _("Gamecube Memory Cards (*.raw,*.gcp)") + wxString(wxT("|*.raw;*.gcp")), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN); m_MemcardList[slot] = new CMemcardListCtrl(this, ID_MEMCARDLIST_A + slot, wxDefaultPosition, wxSize(350,400), @@ -265,7 +265,7 @@ void CMemcardManager::CreateGUIControls() m_Delete[i]->Disable(); if (DefaultMemcard[i].length()) { - m_MemcardPath[i]->SetPath(wxString::From8BitData(DefaultMemcard[i].c_str())); + m_MemcardPath[i]->SetPath(StrToWxStr(DefaultMemcard[i])); ChangePath(i); } } @@ -520,7 +520,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) _("Select a save file to import"), (strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0) ? StrToWxStr("") - : wxString::From8BitData(DefaultIOPath.c_str()), + : StrToWxStr(DefaultIOPath), wxEmptyString, wxEmptyString, _("GameCube Savegame files(*.gci;*.gcs;*.sav)") + wxString(wxT("|*.gci;*.gcs;*.sav|")) + _("Native GCI files(*.gci)") + wxString(wxT("|*.gci|")) + @@ -557,8 +557,8 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) } wxString fileName = wxFileSelector( _("Export save as..."), - wxString::From8BitData(DefaultIOPath.c_str()), - wxString::From8BitData(gciFilename.c_str()), wxT(".gci"), + StrToWxStr(DefaultIOPath), + StrToWxStr(gciFilename), wxT(".gci"), _("Native GCI files(*.gci)") + wxString(wxT("|*.gci|")) + _("MadCatz Gameshark files(*.gcs)") + wxString(wxT("|*.gcs|")) + _("Datel MaxDrive/Pro files(*.sav)") + wxString(wxT("|*.sav")), diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 988ccae83e..60efcedc6f 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -51,7 +51,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::string nickname; netplay_section.Get("Nickname", &nickname, "Player"); - m_nickname_text = new wxTextCtrl(panel, wxID_ANY, wxString::From8BitData(nickname.c_str())); + m_nickname_text = new wxTextCtrl(panel, wxID_ANY, StrToWxStr(nickname)); wxBoxSizer* const nick_szr = new wxBoxSizer(wxHORIZONTAL); nick_szr->Add(nick_lbl, 0, wxCENTER); From 88cb11ba0a24e0fb841b4fc4367f4d61ae18558e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 2 Mar 2013 20:38:40 -0600 Subject: [PATCH 16/26] I'm confused at why SHIFT-JIS was being used here. --- Source/Core/DolphinWX/Src/LogWindow.cpp | 23 ++++------------------- Source/Core/DolphinWX/Src/LogWindow.h | 2 -- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/Source/Core/DolphinWX/Src/LogWindow.cpp b/Source/Core/DolphinWX/Src/LogWindow.cpp index 7af1de1aaa..57e2ac6b58 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.cpp +++ b/Source/Core/DolphinWX/Src/LogWindow.cpp @@ -21,6 +21,8 @@ #include "IniFile.h" #include "FileUtil.h" #include "Debugger/DebuggerUIUtil.h" +#include "WxUtils.h" + #include // Milliseconds between msgQueue flushes to wxTextCtrl @@ -41,25 +43,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos, , x(0), y(0), winpos(0) , Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true) , m_Log(NULL), m_cmdline(NULL), m_FontChoice(NULL) - , m_SJISConv(wxT("")) { -#ifdef _WIN32 - static bool validCP932 = ::IsValidCodePage(932) != 0; - if (validCP932) - { - m_SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS)); - } - else - { - WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932"); - m_SJISConv = *(wxCSConv*)wxConvCurrent; - } -#else - // on linux the wrong string is returned from wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS) - // it returns CP-932, in order to use iconv we need to use CP932 - m_SJISConv = wxCSConv(wxT("CP932")); -#endif - m_LogManager = LogManager::GetInstance(); CreateGUIControls(); @@ -370,5 +354,6 @@ void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text) if (msgQueue.size() >= 100) msgQueue.pop(); - msgQueue.push(std::pair((u8)level, wxString(text, m_SJISConv))); + + msgQueue.push(std::make_pair(u8(level), StrToWxStr(text))); } diff --git a/Source/Core/DolphinWX/Src/LogWindow.h b/Source/Core/DolphinWX/Src/LogWindow.h index 86fd1d3b4f..54a59c4d91 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.h +++ b/Source/Core/DolphinWX/Src/LogWindow.h @@ -75,8 +75,6 @@ private: std::mutex m_LogSection; - wxCSConv m_SJISConv; - DECLARE_EVENT_TABLE() wxTextCtrl * CreateTextCtrl(wxPanel* parent, wxWindowID id = wxID_ANY, long Style = NULL); From aeb4fc9846f19d78248994b72c0902c17df3947b Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 2 Mar 2013 22:57:49 -0600 Subject: [PATCH 17/26] Fix what I broke. --- Source/Core/Common/Src/StringUtil.cpp | 80 +++++++++++- Source/Core/Common/Src/StringUtil.h | 1 + Source/Core/DiscIO/Src/BannerLoader.cpp | 4 +- Source/Core/DiscIO/Src/BannerLoader.h | 6 - Source/Core/DiscIO/Src/BannerLoaderGC.cpp | 11 +- Source/Core/DiscIO/Src/BannerLoaderGC.h | 13 +- Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 139 ++------------------- Source/Core/DiscIO/Src/BannerLoaderWii.h | 3 - Source/Core/DiscIO/Src/Volume.h | 2 + 9 files changed, 108 insertions(+), 151 deletions(-) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index aab0f3bd58..e499fc40c3 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -17,13 +17,19 @@ #include #include +#include #include "Common.h" #include "CommonPaths.h" #include "StringUtil.h" #ifdef _WIN32 -#include + #include +#elif defined(ANDROID) + +#else + #include + #include #endif // faster than sscanf @@ -418,18 +424,80 @@ 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 -std::string UTF16ToUTF8(const std::wstring& input) +template +std::string CodeToUTF8(const char* fromcode, const std::basic_string& input) { - // TODO: implement - return std::string(); + 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(); + + size_t const iconv_size = iconv(conv_desc, (char**)(&src_buffer), &src_bytes, + &dst_buffer, &dst_bytes); + + if ((size_t)-1 == iconv_size) + { + ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno)); + } + else + { + out_buffer.resize(out_buffer_size - dst_bytes); + out_buffer.swap(result); + + // TODO: why is this needed? + result.erase(std::remove(result.begin(), result.end(), 0x00), result.end()); + } + + iconv_close(conv_desc); + } + +#endif + return result; +} + +std::string CP1252ToUTF8(const std::string& input) +{ + return CodeToUTF8("CP1252", input); } std::string SHIFTJISToUTF8(const std::string& input) { - // TODO: implement - return std::string(); + //return CodeToUTF8("CP932", input); + return CodeToUTF8("SJIS", input); +} + +std::string UTF16ToUTF8(const std::wstring& input) +{ + //return CodeToUTF8("UCS-2", input); + //return CodeToUTF8("UCS-2LE", input); + //return CodeToUTF8("UTF-16", input); + return CodeToUTF8("UTF-16LE", input); } #endif diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index ce5751f80b..9463db5bb1 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -97,6 +97,7 @@ 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); diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index 7e641aa85b..d38c7e9ea4 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -31,9 +31,9 @@ IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVo { return new CBannerLoaderWii(pVolume); } - if (_rFileSystem.IsValid()) + if (_rFileSystem.IsValid()) { - return new CBannerLoaderGC(_rFileSystem); + return new CBannerLoaderGC(_rFileSystem, pVolume); } return NULL; diff --git a/Source/Core/DiscIO/Src/BannerLoader.h b/Source/Core/DiscIO/Src/BannerLoader.h index 92bb874979..b30ee17a46 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.h +++ b/Source/Core/DiscIO/Src/BannerLoader.h @@ -44,12 +44,6 @@ class IBannerLoader virtual std::vector GetNames() = 0; virtual std::string GetCompany() = 0; virtual std::vector GetDescriptions() = 0; - - private: - u16 swap16(u16 data) - { - return ((data & 0xff00) >> 8) | ((data & 0xff) << 8); - } }; IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume); diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp index bf087cbfb6..d8ae259b16 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp @@ -23,9 +23,10 @@ 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"); @@ -104,7 +105,7 @@ std::vector CBannerLoaderGC::GetNames() auto const banner = reinterpret_cast(m_pBannerFile); - for (int i = 0; i != name_count; ++i) + for (u32 i = 0; i != name_count; ++i) { auto& comment = banner->comment[i]; @@ -167,7 +168,7 @@ std::vector CBannerLoaderGC::GetDescriptions() auto banner = reinterpret_cast(m_pBannerFile); - for (int i = 0; i != desc_count; ++i) + for (u32 i = 0; i != desc_count; ++i) { auto& data = banner->comment[i].comment; descriptions.push_back(GetDecodedString(data)); diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.h b/Source/Core/DiscIO/Src/BannerLoaderGC.h index b4903561e4..8bc8c46483 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.h +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.h @@ -19,6 +19,7 @@ #define _BANNER_LOADER_GC_H_ #include "BannerLoader.h" +#include "StringUtil.h" namespace DiscIO { @@ -26,7 +27,7 @@ class CBannerLoaderGC : public IBannerLoader { public: - CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem); + CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume); virtual ~CBannerLoaderGC(); virtual bool IsValid(); @@ -76,8 +77,12 @@ class CBannerLoaderGC template std::string GetDecodedString(const char (&data)[N]) { - // Can I always assume SHIFT-JIS? - return SHIFTJISToUTF8(std::string(data, strnlen(data, sizeof(data)))); + auto const string_decoder = (DiscIO::IVolume::COUNTRY_JAPAN == m_country || + DiscIO::IVolume::COUNTRY_TAIWAN == m_country) ? + SHIFTJISToUTF8 : CP1252ToUTF8; + + // strnlen to trim NULLs + return string_decoder(std::string(data, strnlen(data, sizeof(data)))); } u8* m_pBannerFile; @@ -86,6 +91,8 @@ class CBannerLoaderGC void decode5A3image(u32* dst, u16* src, int width, int height); BANNER_TYPE getBannerType(); + + DiscIO::IVolume::ECountry const m_country; }; } // namespace diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index b94e299f04..f606ed8876 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -25,25 +25,6 @@ #include "FileUtil.h" #include "FileHandlerARC.h" -// HyperIris: dunno if this suitable, may be need move. -#ifdef _WIN32 -#include -#else -#include -#ifndef ANDROID -#include -#endif -#include -#endif - -#ifndef ICONV_CONST -#if defined __FreeBSD__ || __NetBSD__ -#define ICONV_CONST const -#else -#define ICONV_CONST -#endif -#endif - namespace DiscIO { @@ -164,35 +145,24 @@ 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; - // TODO: trim NULLs - ret = CopyBeUnicodeToString(s, pBanner->m_Comment[index], COMMENT_SIZE); - } - - 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(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; } @@ -237,87 +207,4 @@ void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) } } -bool CBannerLoaderWii::CopyBeUnicodeToString( std::string& _rDestination, const u16* _src, int length ) -{ - bool returnCode = false; -#ifdef _WIN32 - if (_src) - { - std::wstring src; - src.resize(length); - std::transform(_src, _src + length, &src[0], (u16(&)(u16))Common::swap16); - - _rDestination = UTF16ToUTF8(src); - returnCode = true; - } -#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; -} - } // namespace diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.h b/Source/Core/DiscIO/Src/BannerLoaderWii.h index 60d317155b..036eeeacbd 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.h +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.h @@ -75,9 +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); - - bool CopyBeUnicodeToString(std::string& _rDestination, const u16* _src, int length); }; } // namespace diff --git a/Source/Core/DiscIO/Src/Volume.h b/Source/Core/DiscIO/Src/Volume.h index 4743cfce89..c19aaf93a8 100644 --- a/Source/Core/DiscIO/Src/Volume.h +++ b/Source/Core/DiscIO/Src/Volume.h @@ -22,6 +22,7 @@ #include #include "Common.h" +#include "StringUtil.h" namespace DiscIO { @@ -37,6 +38,7 @@ public: virtual void GetTMD(u8*, u32 *_sz) const { *_sz=0; } virtual std::string GetUniqueID() const = 0; virtual std::string GetMakerID() const = 0; + // TODO: eliminate? virtual std::string GetName() const; virtual std::vector GetNames() const = 0; virtual u32 GetFSTSize() const = 0; From fad2b65d76dc9f0108c5ed3638c4d1ec6403c00e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 02:30:45 -0600 Subject: [PATCH 18/26] More wxString conversion cleanup. --- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 3 +-- Source/Core/DolphinWX/Src/MemcardManager.cpp | 25 ++++---------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 562d2234cd..15df0fa3ee 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -966,8 +966,7 @@ void CGameListCtrl::OnOpenContainingFolder(wxCommandEvent& WXUNUSED (event)) if (!iso) return; - wxString strPath(iso->GetFileName().c_str(), wxConvUTF8); - wxFileName path = wxFileName::FileName(strPath); + wxFileName path = wxFileName::FileName(StrToWxStr(iso->GetFileName())); path.MakeAbsolute(); WxUtils::Explore(path.GetPath().char_str()); } diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index b9b26b6da8..0bbbbd0a7b 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -704,26 +704,11 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card) std::string title = memoryCard[card]->GetSaveComment1(fileIndex); std::string comment = memoryCard[card]->GetSaveComment2(fileIndex); - bool ascii = memoryCard[card]->IsAsciiEncoding(); - -#ifdef _WIN32 - wxCSConv SJISConv(*(wxCSConv*)wxConvCurrent); - static bool validCP932 = ::IsValidCodePage(932) != 0; - if (validCP932) - { - SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS)); - } - else - { - WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932"); - } -#else - // on linux the wrong string is returned from wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS) - // it returns CP-932, in order to use iconv we need to use CP932 - wxCSConv SJISConv(wxT("CP932")); -#endif - wxTitle = wxString(title.c_str(), ascii ? *wxConvCurrent : SJISConv); - wxComment = wxString(comment.c_str(), ascii ? *wxConvCurrent : SJISConv); + auto const string_decoder = memoryCard[card]->IsAsciiEncoding() ? + CP1252ToUTF8 : SHIFTJISToUTF8; + + wxTitle = StrToWxStr(string_decoder(title)); + wxComment = StrToWxStr(string_decoder(comment)); m_MemcardList[card]->SetItem(index, COLUMN_TITLE, wxTitle); m_MemcardList[card]->SetItem(index, COLUMN_COMMENT, wxComment); From c07b8a6e3754abb4be5d962d84550d4b10827240 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 16:51:26 -0600 Subject: [PATCH 19/26] Fix more of what I broke. --- Source/Core/Common/Src/StringUtil.cpp | 52 ++++++++++++++------- Source/Core/DiscIO/Src/BannerLoaderGC.h | 5 +- Source/Core/DiscIO/Src/FileSystemGCWii.cpp | 32 +++++++------ Source/Core/DiscIO/Src/FileSystemGCWii.h | 6 +-- Source/Core/DiscIO/Src/VolumeGC.cpp | 14 ++++-- Source/Core/DiscIO/Src/VolumeGC.h | 4 ++ Source/Core/DiscIO/Src/VolumeWad.cpp | 38 +++++++-------- Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp | 7 +-- 8 files changed, 97 insertions(+), 61 deletions(-) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index e499fc40c3..c38184776b 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -457,22 +457,33 @@ std::string CodeToUTF8(const char* fromcode, const std::basic_string& input) size_t src_bytes = in_bytes; auto dst_buffer = &out_buffer[0]; size_t dst_bytes = out_buffer.size(); - - size_t const iconv_size = iconv(conv_desc, (char**)(&src_buffer), &src_bytes, - &dst_buffer, &dst_bytes); - - if ((size_t)-1 == iconv_size) + + while (src_bytes != 0) { - ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno)); - } - else - { - out_buffer.resize(out_buffer_size - dst_bytes); - out_buffer.swap(result); + size_t const iconv_result = iconv(conv_desc, (char**)(&src_buffer), &src_bytes, + &dst_buffer, &dst_bytes); - // TODO: why is this needed? - result.erase(std::remove(result.begin(), result.end(), 0x00), result.end()); + if ((size_t)-1 == iconv_result) + { + if (EILSEQ == errno || EINVAL == errno) + { + // Try to skip the bad character + if (src_bytes != 0) + { + --src_bytes; + ++src_buffer; + } + } + else + { + ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno)); + break; + } + } } + + out_buffer.resize(out_buffer_size - dst_bytes); + out_buffer.swap(result); iconv_close(conv_desc); } @@ -483,6 +494,8 @@ std::string CodeToUTF8(const char* fromcode, const std::basic_string& input) std::string CP1252ToUTF8(const std::string& input) { + //return CodeToUTF8("CP1252//TRANSLIT", input); + //return CodeToUTF8("CP1252//IGNORE", input); return CodeToUTF8("CP1252", input); } @@ -494,10 +507,15 @@ std::string SHIFTJISToUTF8(const std::string& input) std::string UTF16ToUTF8(const std::wstring& input) { - //return CodeToUTF8("UCS-2", input); - //return CodeToUTF8("UCS-2LE", input); - //return CodeToUTF8("UTF-16", input); - return CodeToUTF8("UTF-16LE", input); + std::string result = + // CodeToUTF8("UCS-2", input); + // CodeToUTF8("UCS-2LE", input); + // CodeToUTF8("UTF-16", input); + CodeToUTF8("UTF-16LE", input); + + // TODO: why is this needed? + result.erase(std::remove(result.begin(), result.end(), 0x00), result.end()); + return result; } #endif diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.h b/Source/Core/DiscIO/Src/BannerLoaderGC.h index 8bc8c46483..8b14a45d43 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.h +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.h @@ -19,6 +19,7 @@ #define _BANNER_LOADER_GC_H_ #include "BannerLoader.h" +#include "VolumeGC.h" #include "StringUtil.h" namespace DiscIO @@ -77,9 +78,7 @@ class CBannerLoaderGC template std::string GetDecodedString(const char (&data)[N]) { - auto const string_decoder = (DiscIO::IVolume::COUNTRY_JAPAN == m_country || - DiscIO::IVolume::COUNTRY_TAIWAN == m_country) ? - SHIFTJISToUTF8 : CP1252ToUTF8; + auto const string_decoder = CVolumeGC::GetStringDecoder(m_country); // strnlen to trim NULLs return string_decoder(std::string(data, strnlen(data, sizeof(data)))); diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp index 47651e2f23..93b569e043 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "FileSystemGCWii.h" #include "StringUtil.h" @@ -27,10 +28,10 @@ namespace DiscIO { CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume) - : IFileSystem(_rVolume), - m_Initialized(false), - m_Valid(false), - m_OffsetShift(0) + : IFileSystem(_rVolume) + , m_Initialized(false) + , m_Valid(false) + , m_OffsetShift(0) { m_Valid = DetectFileSystem(); } @@ -213,9 +214,16 @@ u32 CFileSystemGCWii::Read32(u64 _Offset) const return Common::swap32(Temp); } -void CFileSystemGCWii::GetStringFromOffset(u64 _Offset, char* Filename) const +std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const { - m_rVolume->Read(_Offset, 255, (u8*)Filename); + std::string data; + data.resize(255); + m_rVolume->Read(_Offset, data.size(), (u8*)&data[0]); + data.erase(std::find(data.begin(), data.end(), 0x00), data.end()); + + // TODO: Should we really always use SHIFT-JIS? + // It makes some filenames in Pikmin (NTSC-U) sane, but is it correct? + return SHIFTJISToUTF8(data); } size_t CFileSystemGCWii::GetFileList(std::vector &_rFilenames) @@ -311,18 +319,16 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _ { SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex]; u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF); - char filename[512]; - memset(filename, 0, sizeof(filename)); - GetStringFromOffset(uOffset, filename); + std::string filename = GetStringFromOffset(uOffset); // check next index if (rFileInfo->IsDirectory()) { // this is a directory, build up the new szDirectory if (_szDirectory != NULL) - CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename); + CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename.c_str()); else - CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename); + CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename.c_str()); CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset); } @@ -330,9 +336,9 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _ { // this is a filename if (_szDirectory != NULL) - CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename); + CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename.c_str()); else - CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename); + CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename.c_str()); CurrentIndex++; } diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.h b/Source/Core/DiscIO/Src/FileSystemGCWii.h index 0e7d836d75..9054ade272 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.h +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.h @@ -28,7 +28,7 @@ namespace DiscIO class CFileSystemGCWii : public IFileSystem { public: - CFileSystemGCWii(const IVolume *_rVolume); + CFileSystemGCWii(const IVolume* _rVolume); virtual ~CFileSystemGCWii(); virtual bool IsValid() const { return m_Valid; } virtual u64 GetFileSize(const char* _rFullPath); @@ -44,11 +44,11 @@ public: private: bool m_Initialized; bool m_Valid; - u32 m_OffsetShift; // WII offsets are all shifted + std::vector 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(); diff --git a/Source/Core/DiscIO/Src/VolumeGC.cpp b/Source/Core/DiscIO/Src/VolumeGC.cpp index 6e9579571a..6210172790 100644 --- a/Source/Core/DiscIO/Src/VolumeGC.cpp +++ b/Source/Core/DiscIO/Src/VolumeGC.cpp @@ -94,10 +94,12 @@ std::string CVolumeGC::GetMakerID() const std::vector CVolumeGC::GetNames() const { std::vector names; + + auto const string_decoder = GetStringDecoder(GetCountry()); - char name[128] = {}; - if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name)) - names.push_back(name); + char name[0x60 + 1] = {}; + if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name)) + names.push_back(string_decoder(name)); return names; } @@ -143,4 +145,10 @@ bool CVolumeGC::IsDiscTwo() const return discTwo; } +auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder +{ + return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ? + SHIFTJISToUTF8 : CP1252ToUTF8; +} + } // namespace diff --git a/Source/Core/DiscIO/Src/VolumeGC.h b/Source/Core/DiscIO/Src/VolumeGC.h index dab1ad7a9d..d7729ee04c 100644 --- a/Source/Core/DiscIO/Src/VolumeGC.h +++ b/Source/Core/DiscIO/Src/VolumeGC.h @@ -40,6 +40,10 @@ public: ECountry GetCountry() const; u64 GetSize() const; bool IsDiscTwo() const; + + typedef std::string(*StringDecoder)(const std::string&); + + static StringDecoder GetStringDecoder(ECountry country); private: IBlobReader* m_pReader; diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp index 72788f1017..ed95774b2e 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.cpp +++ b/Source/Core/DiscIO/Src/VolumeWad.cpp @@ -15,6 +15,7 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ +#include #include #include "VolumeWad.h" @@ -117,33 +118,32 @@ std::vector CVolumeWAD::GetNames() const { return names; } + + footer_size = Common::swap32(footer_size); + //Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean - - // Offset to the english title - for (int i = 0; i < 10; i++) + for (int i = 0; i != 10; ++i) { - u16 temp[42]; - std::wstring out_temp; + static const u32 string_length = 42; + static const u32 bytes_length = string_length * sizeof(u16); + + u16 temp[string_length]; - if (!Read(0x9C + (i*84) + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1 - || !temp[0]) + if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + OpeningBnrOffset, bytes_length, (u8*)&temp)) { names.push_back(""); - continue; + ERROR_LOG(COMMON, "added empty WAD name"); } - for (int j = 0; j < 42; ++j) + else { - u16 t = Common::swap16(temp[j]); - if (t == 0 && j > 0) - { - if (out_temp.at(out_temp.size()-1) != ' ') - out_temp.push_back(' '); - } - else - out_temp.push_back(t); + std::wstring out_temp; + out_temp.resize(string_length); + std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); + out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); + + names.push_back(UTF16ToUTF8(out_temp)); + ERROR_LOG(COMMON, "decoded WAD name: %s", names.back().c_str()); } - - names.push_back(UTF16ToUTF8(out_temp)); } return names; diff --git a/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp index f375b9e66d..32aa92bd08 100644 --- a/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "VolumeWiiCrypted.h" +#include "VolumeGC.h" #include "StringUtil.h" #include "Crypto/sha1.h" @@ -171,12 +172,12 @@ std::string CVolumeWiiCrypted::GetMakerID() const std::vector CVolumeWiiCrypted::GetNames() const { std::vector names; + + auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry()); char name[0xFF] = {}; if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name)) - { - names.push_back(name); - } + names.push_back(string_decoder(name)); return names; } From ae14578bc5bddd5ebc3e97483dc844bfe5a0e7de Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 17:56:40 -0600 Subject: [PATCH 20/26] Eliminate some netplay gamelist ugliness. --- Source/Core/Core/Src/NetPlay.h | 2 +- Source/Core/DolphinWX/Src/Frame.cpp | 4 +- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 34 +++------------ Source/Core/DolphinWX/Src/GameListCtrl.h | 8 ---- Source/Core/DolphinWX/Src/NetWindow.cpp | 50 +++++++++++----------- 5 files changed, 36 insertions(+), 62 deletions(-) diff --git a/Source/Core/Core/Src/NetPlay.h b/Source/Core/Core/Src/NetPlay.h index e77f972785..96ff78995a 100644 --- a/Source/Core/Core/Src/NetPlay.h +++ b/Source/Core/Core/Src/NetPlay.h @@ -34,7 +34,7 @@ struct Rpt : public std::vector typedef std::vector NetWiimote; -#define NETPLAY_VERSION "Dolphin NetPlay r6423" +#define NETPLAY_VERSION "Dolphin NetPlay 2013-03-03" // messages enum diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp index b0b53cc5ea..a0a030081e 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -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) && @@ -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 diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 15df0fa3ee..1a828bbf14 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -285,10 +285,6 @@ void CGameListCtrl::Update() m_imageListSmall = NULL; } - // NetPlay : Set/Reset the GameList string - m_gameList.clear(); - m_gamePath.clear(); - Hide(); ScanForISOs(); @@ -406,15 +402,6 @@ wxString NiceSizeFormat(s64 _size) return(NiceString); } -std::string CGameListCtrl::GetGamePaths() const -{ - return m_gamePath; -} -std::string CGameListCtrl::GetGameNames() const -{ - return m_gameList; -} - void CGameListCtrl::InsertItemInReportView(long _Index) { // When using wxListCtrl, there is no hope of per-column text colors. @@ -424,7 +411,6 @@ void CGameListCtrl::InsertItemInReportView(long _Index) int ImageIndex = -1; GameListItem& rISOFile = *m_ISOFiles[_Index]; - m_gamePath.append(rISOFile.GetFileName() + '\n'); // Insert a first row with nothing in it, that will be used as the Index long ItemIndex = InsertItem(_Index, wxEmptyString); @@ -438,31 +424,25 @@ void CGameListCtrl::InsertItemInReportView(long _Index) // Set the game's banner in the second column SetItemColumnImage(_Index, COLUMN_BANNER, ImageIndex); - std::string name; - int SelectedLanguage = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; + + // Is this sane? switch (rISOFile.GetCountry()) { case DiscIO::IVolume::COUNTRY_TAIWAN: case DiscIO::IVolume::COUNTRY_JAPAN: - { - name = rISOFile.GetName(-1); - m_gameList.append(StringFromFormat("%s (J)\n", name.c_str())); - } + SelectedLanguage = -1; break; + case DiscIO::IVolume::COUNTRY_USA: - // Is this sane? SelectedLanguage = 0; + break; + default: - { - name = rISOFile.GetName(SelectedLanguage); - m_gameList.append(StringFromFormat("%s (%c)\n", name.c_str(), - (rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E')); - - } break; } + std::string const name = rISOFile.GetName(SelectedLanguage); SetItem(_Index, COLUMN_TITLE, StrToWxStr(name), -1); // We show the company string on Gamecube only diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.h b/Source/Core/DolphinWX/Src/GameListCtrl.h index 5d97c12724..f1923e97c5 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.h +++ b/Source/Core/DolphinWX/Src/GameListCtrl.h @@ -47,10 +47,6 @@ public: void Update(); - // Net Play method - std::string GetGamePaths() const; - std::string GetGameNames() const; - void BrowseForDirectory(); const GameListItem *GetSelectedISO(); const GameListItem *GetISO(size_t index) const; @@ -84,10 +80,6 @@ private: } } - // NetPlay string for the gamelist - std::string m_gameList; - std::string m_gamePath; - int last_column; int last_sort; wxSize lastpos; diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 60efcedc6f..8cfe41dc93 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -24,6 +24,7 @@ #include "Frame.h" #include +#include #define NETPLAY_TITLEBAR "Dolphin NetPlay" @@ -35,6 +36,21 @@ static NetPlay* netplay_ptr = NULL; extern CFrame* main_frame; NetPlayDiag *NetPlayDiag::npd = NULL; +std::string BuildGameName(const GameListItem& game) +{ + auto const selected_lang = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; + + // TODO: this should use the name from the volume not the banner + // (I seems banner name can sometimes depend on save contents) + return game.GetName(selected_lang) + " (" + game.GetUniqueID() + ")"; +} + +void FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list) +{ + for (u32 i = 0 ; auto game = game_list.GetISO(i); ++i) + game_lbox->Append(StrToWxStr(BuildGameName(*game))); +} + NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list) : wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) , m_game_list(game_list) @@ -121,11 +137,8 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* m_game_lbox = new wxListBox(host_tab, wxID_ANY); m_game_lbox->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &NetPlaySetupDiag::OnHost, this); - - std::istringstream ss(game_list->GetGameNames()); - std::string game; - while (std::getline(ss,game)) - m_game_lbox->Append(StrToWxStr(game)); + + FillWithGameNames(m_game_lbox, *game_list); wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT, 5); @@ -360,24 +373,17 @@ void NetPlayDiag::OnChat(wxCommandEvent&) void NetPlayDiag::OnStart(wxCommandEvent&) { - // find path for selected game - std::string ntmp, ptmp, path; - std::istringstream nss(m_game_list->GetGameNames()), pss(m_game_list->GetGamePaths()); - - while(std::getline(nss,ntmp)) + // find path for selected game, sloppy.. + for (u32 i = 0 ; auto game = m_game_list->GetISO(i); ++i) { - std::getline(pss,ptmp); - if (m_selected_game == ntmp) + if (m_selected_game == BuildGameName(*game)) { - path = ptmp; - break; + netplay_ptr->StartGame(game->GetFileName()); + return; } } - - if (path.length()) - netplay_ptr->StartGame(path); - else - PanicAlertT("Game not found!!"); + + PanicAlertT("Game not found!"); } void NetPlayDiag::OnStop(wxCommandEvent&) @@ -550,11 +556,7 @@ ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* cons m_game_lbox = new wxListBox(this, wxID_ANY); m_game_lbox->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &ChangeGameDiag::OnPick, this); - // fill list with games - std::istringstream ss(game_list->GetGameNames()); - std::string game; - while (std::getline(ss,game)) - m_game_lbox->Append(StrToWxStr(game)); + FillWithGameNames(m_game_lbox, *game_list); wxButton* const ok_btn = new wxButton(this, wxID_OK, _("Change")); ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ChangeGameDiag::OnPick, this); From a30636cb88679d5f7a886aba6e5de83f4123f968 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 18:00:48 -0600 Subject: [PATCH 21/26] Buildfix. --- Source/Core/DolphinWX/Src/NetWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 8cfe41dc93..28c7f930d7 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -22,6 +22,7 @@ #include "NetPlay.h" #include "NetWindow.h" #include "Frame.h" +#include "ConfigManager.h" #include #include From 6026b298449f480ea96285242c4ed9253c854a22 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 18:29:56 -0600 Subject: [PATCH 22/26] Separate banner and volume name getting functions. Game properties now shows the correct "banner" name in more cases. --- Source/Core/DolphinWX/Src/ISOFile.cpp | 50 +++++++++++++++------ Source/Core/DolphinWX/Src/ISOFile.h | 2 + Source/Core/DolphinWX/Src/ISOProperties.cpp | 21 ++++----- Source/Core/DolphinWX/Src/NetWindow.cpp | 12 ++--- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index ec8280a726..797780c32e 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -226,28 +226,50 @@ std::string GameListItem::GetDescription(int _index) const } // (-1 = Japanese, 0 = English, etc) -std::string GameListItem::GetName(int _index) const +std::string GameListItem::GetVolumeName(int _index) const { u32 const index = _index + 1; - // banner name - if (index < m_names.size() && !m_names[index].empty()) - return m_names[index]; - - if (!m_names.empty() && !m_names[0].empty()) - return m_names[0]; - - // volume name if (index < m_volume_names.size() && !m_volume_names[index].empty()) return m_volume_names[index]; - if (!m_volume_names.empty() && !m_volume_names[0].empty()) + if (!m_volume_names.empty()) return m_volume_names[0]; + + return ""; +} - // No usable name, return filename (better than nothing) - std::string FileName; - SplitPath(m_FileName, NULL, &FileName, NULL); - return FileName; +// (-1 = Japanese, 0 = English, etc) +std::string GameListItem::GetBannerName(int _index) const +{ + u32 const index = _index + 1; + + if (index < m_names.size() && !m_names[index].empty()) + return m_names[index]; + + if (!m_names.empty()) + return m_names[0]; + + return ""; +} + +// (-1 = Japanese, 0 = English, etc) +std::string GameListItem::GetName(int _index) const +{ + // Prefer name from banner, fallback to name from volume, fallback to filename + + std::string name = GetBannerName(_index); + + if (name.empty()) + name = GetVolumeName(_index); + + if (name.empty()) + { + // No usable name, return filename (better than nothing) + SplitPath(GetFileName(), NULL, &name, NULL); + } + + return name; } const std::string GameListItem::GetWiiFSPath() const diff --git a/Source/Core/DolphinWX/Src/ISOFile.h b/Source/Core/DolphinWX/Src/ISOFile.h index ded392f56a..354a2f7fad 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.h +++ b/Source/Core/DolphinWX/Src/ISOFile.h @@ -37,6 +37,8 @@ public: bool IsValid() const {return m_Valid;} const std::string& GetFileName() const {return m_FileName;} + std::string GetBannerName(int index) const; + std::string GetVolumeName(int index) const; std::string GetName(int index) const; std::string GetCompany() const; std::string GetDescription(int index = 0) const; diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 43657300cb..f6ca1cb851 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -1301,28 +1301,25 @@ void CISOProperties::OnChangeBannerLang(wxCommandEvent& event) void CISOProperties::ChangeBannerDetails(int lang) { - std::string name; - wxString shortName, - comment, - maker; - + // why? switch (OpenGameListItem->GetCountry()) { case DiscIO::IVolume::COUNTRY_TAIWAN: case DiscIO::IVolume::COUNTRY_JAPAN: - shortName = StrToWxStr(OpenGameListItem->GetName(-1)); - comment = StrToWxStr(OpenGameListItem->GetDescription()); + lang = -1; break; + case DiscIO::IVolume::COUNTRY_USA: - // why? lang = 0; + break; + default: - shortName = StrToWxStr(OpenGameListItem->GetName(lang)); - comment = StrToWxStr(OpenGameListItem->GetDescription(lang)); break; } - - maker = StrToWxStr(OpenGameListItem->GetCompany()); + + wxString const shortName = StrToWxStr(OpenGameListItem->GetBannerName(lang)); + wxString const comment = StrToWxStr(OpenGameListItem->GetDescription(lang)); + wxString const maker = StrToWxStr(OpenGameListItem->GetCompany()); // Updates the informations shown in the window m_ShortName->SetValue(shortName); diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 28c7f930d7..76bb76881b 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -22,7 +22,6 @@ #include "NetPlay.h" #include "NetWindow.h" #include "Frame.h" -#include "ConfigManager.h" #include #include @@ -39,11 +38,14 @@ NetPlayDiag *NetPlayDiag::npd = NULL; std::string BuildGameName(const GameListItem& game) { - auto const selected_lang = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage; + // Lang needs to be consistent + auto const lang = 0; - // TODO: this should use the name from the volume not the banner - // (I seems banner name can sometimes depend on save contents) - return game.GetName(selected_lang) + " (" + game.GetUniqueID() + ")"; + std::string name(game.GetBannerName(lang)); + if (name.empty()) + name = game.GetVolumeName(lang); + + return name + " (" + game.GetUniqueID() + ")"; } void FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list) From bdc96342baa369fc63c013ce385aa780e096ff8f Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 18:40:50 -0600 Subject: [PATCH 23/26] More string conversion cleanup. --- Source/Core/DolphinWX/Src/LogWindow.cpp | 2 +- Source/Core/DolphinWX/Src/Main.cpp | 2 +- Source/Core/DolphinWX/Src/VideoConfigDiag.cpp | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinWX/Src/LogWindow.cpp b/Source/Core/DolphinWX/Src/LogWindow.cpp index 57e2ac6b58..27e5856410 100644 --- a/Source/Core/DolphinWX/Src/LogWindow.cpp +++ b/Source/Core/DolphinWX/Src/LogWindow.cpp @@ -192,7 +192,7 @@ void CLogWindow::SaveSettings() void CLogWindow::OnSubmit(wxCommandEvent& WXUNUSED (event)) { if (!m_cmdline) return; - Console_Submit(m_cmdline->GetValue().To8BitData()); + Console_Submit(WxStrToStr(m_cmdline->GetValue()).c_str()); m_cmdline->SetValue(wxEmptyString); } diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 60a8157c28..09387f2764 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -445,7 +445,7 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style* std::string wxStringTranslator(const char *text) { - return WxStrToStr(wxGetTranslation(wxString::From8BitData(text))); + return WxStrToStr(wxGetTranslation(wxString::FromUTF8(text))); } // Accessor for the main window class diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp index 154a5bc602..cf44c231fe 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp @@ -180,8 +180,7 @@ wxArrayString GetListOfResolutions() VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, const std::string& _ininame) : wxDialog(parent, -1, - wxString::Format(_("Dolphin %s Graphics Configuration"), - wxGetTranslation(wxString::From8BitData(title.c_str()))), + wxString::Format(_("Dolphin %s Graphics Configuration"), wxGetTranslation(StrToWxStr(title))), wxDefaultPosition, wxDefaultSize) , vconfig(g_Config) , ininame(_ininame) From 6b2818199c0674abcbd40b258ca9de2d65d0d132 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 19:00:29 -0600 Subject: [PATCH 24/26] Fix WAD volume name extracting. --- Source/Core/DiscIO/Src/VolumeWad.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp index ed95774b2e..a10e5bdb42 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.cpp +++ b/Source/Core/DiscIO/Src/VolumeWad.cpp @@ -111,7 +111,6 @@ bool CVolumeWAD::GetTitleID(u8* _pBuffer) const std::vector CVolumeWAD::GetNames() const { std::vector names; - return names; u32 footer_size; if (!Read(0x1C, 4, (u8*)&footer_size)) @@ -132,7 +131,6 @@ std::vector CVolumeWAD::GetNames() const if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + OpeningBnrOffset, bytes_length, (u8*)&temp)) { names.push_back(""); - ERROR_LOG(COMMON, "added empty WAD name"); } else { @@ -142,7 +140,6 @@ std::vector CVolumeWAD::GetNames() const out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); names.push_back(UTF16ToUTF8(out_temp)); - ERROR_LOG(COMMON, "decoded WAD name: %s", names.back().c_str()); } } From 989f0663eb212164e11e80626fa89900d2f1ae3e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 19:14:13 -0600 Subject: [PATCH 25/26] Make "Crypto" file opening unicode-safe on Windows. --- Source/Core/Common/Src/Crypto/md5.cpp | 9 ++++++--- Source/Core/Common/Src/Crypto/sha1.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/Src/Crypto/md5.cpp b/Source/Core/Common/Src/Crypto/md5.cpp index 7fff7713da..ef31636aea 100644 --- a/Source/Core/Common/Src/Crypto/md5.cpp +++ b/Source/Core/Common/Src/Crypto/md5.cpp @@ -37,6 +37,8 @@ #include #include +#include "FileUtil.h" + /* * 32-bit integer manipulation macros (little endian) */ @@ -301,7 +303,10 @@ int md5_file( char *path, unsigned char output[16] ) md5_context ctx; unsigned char buf[1024]; - if( ( f = fopen( path, "rb" ) ) == NULL ) + File::IOFile file(path, "rb"); + f = file.GetHandle(); + + if (f == NULL) return( 1 ); md5_starts( &ctx ); @@ -315,11 +320,9 @@ int md5_file( char *path, unsigned char output[16] ) if( ferror( f ) != 0 ) { - fclose( f ); return( 2 ); } - fclose( f ); return( 0 ); } diff --git a/Source/Core/Common/Src/Crypto/sha1.cpp b/Source/Core/Common/Src/Crypto/sha1.cpp index 17ad930986..3d26dc8a50 100644 --- a/Source/Core/Common/Src/Crypto/sha1.cpp +++ b/Source/Core/Common/Src/Crypto/sha1.cpp @@ -36,6 +36,8 @@ #include #include +#include "FileUtil.h" + /* * 32-bit integer manipulation macros (big endian) */ @@ -335,7 +337,10 @@ int sha1_file( char *path, unsigned char output[20] ) sha1_context ctx; unsigned char buf[1024]; - if( ( f = fopen( path, "rb" ) ) == NULL ) + File::IOFile file(path, "rb"); + f = file.GetHandle(); + + if (f == NULL) return( 1 ); sha1_starts( &ctx ); @@ -349,11 +354,9 @@ int sha1_file( char *path, unsigned char output[20] ) if( ferror( f ) != 0 ) { - fclose( f ); return( 2 ); } - fclose( f ); return( 0 ); } From 814c2ffdfd213dfa78078471d298e2657b7e14e9 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 19:18:04 -0600 Subject: [PATCH 26/26] Fix some leaking file handles and buildfix probably. --- Source/Core/Common/Src/ArmCPUDetect.cpp | 17 +++++++++-------- Source/Core/Common/Src/Crypto/md5.cpp | 2 +- Source/Core/Common/Src/Crypto/sha1.cpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/Core/Common/Src/ArmCPUDetect.cpp b/Source/Core/Common/Src/ArmCPUDetect.cpp index c03ab08c48..8b5cbf9b79 100644 --- a/Source/Core/Common/Src/ArmCPUDetect.cpp +++ b/Source/Core/Common/Src/ArmCPUDetect.cpp @@ -18,6 +18,7 @@ #include "Common.h" #include "CPUDetect.h" #include "StringUtil.h" +#include "FileUtil.h" const char procfile[] = "/proc/cpuinfo"; @@ -27,9 +28,9 @@ char *GetCPUString() char *cpu_string = 0; // Count the number of processor lines in /proc/cpuinfo char buf[1024]; - FILE *fp; - fp = fopen(procfile, "r"); + File::IOFile file(procfile, "r"); + auto const fp = file.GetHandle(); if (!fp) return 0; @@ -47,9 +48,9 @@ bool CheckCPUFeature(const char *feature) { const char marker[] = "Features\t: "; char buf[1024]; - FILE *fp; - - fp = fopen(procfile, "r"); + + File::IOFile file(procfile, "r"); + auto const fp = file.GetHandle(); if (!fp) return 0; @@ -73,9 +74,9 @@ int GetCoreCount() const char marker[] = "processor\t: "; int cores = 0; char buf[1024]; - FILE *fp; - - fp = fopen(procfile, "r"); + + File::IOFile file(procfile, "r"); + auto const fp = file.GetHandle(); if (!fp) return 0; diff --git a/Source/Core/Common/Src/Crypto/md5.cpp b/Source/Core/Common/Src/Crypto/md5.cpp index ef31636aea..7b8dc149f4 100644 --- a/Source/Core/Common/Src/Crypto/md5.cpp +++ b/Source/Core/Common/Src/Crypto/md5.cpp @@ -37,7 +37,7 @@ #include #include -#include "FileUtil.h" +#include "../FileUtil.h" /* * 32-bit integer manipulation macros (little endian) diff --git a/Source/Core/Common/Src/Crypto/sha1.cpp b/Source/Core/Common/Src/Crypto/sha1.cpp index 3d26dc8a50..45b88b2b6e 100644 --- a/Source/Core/Common/Src/Crypto/sha1.cpp +++ b/Source/Core/Common/Src/Crypto/sha1.cpp @@ -36,7 +36,7 @@ #include #include -#include "FileUtil.h" +#include "../FileUtil.h" /* * 32-bit integer manipulation macros (big endian)