diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 7d8ec15f0c..3e674c0da8 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -327,16 +327,16 @@ void CGameListCtrl::InsertItemInReportView(long _Index) //SetItem(_Index, COLUMN_TITLE, wxString(wxString(rISOFile.GetName()).wc_str(convFrom) , convTo), -1); //SetItem(_Index, COLUMN_NOTES, wxString(wxString(rISOFile.GetDescription()).wc_str(convFrom) , convTo), -1); - if (CopySJISToString(name, rISOFile.GetName(0).c_str())) + if (WxUtils::CopySJISToString(name, rISOFile.GetName(0).c_str())) SetItem(_Index, COLUMN_TITLE, name, -1); - if (CopySJISToString(description, rISOFile.GetDescription(0).c_str())) + if (WxUtils::CopySJISToString(description, rISOFile.GetDescription(0).c_str())) SetItem(_Index, COLUMN_NOTES, description, -1); m_gameList.append(StringFromFormat("%s (J)\n", (const char*)name.mb_str(wxConvUTF8))); break; case DiscIO::IVolume::COUNTRY_USA: - if (CopySJISToString(name, rISOFile.GetName(0).c_str())) + if (WxUtils::CopySJISToString(name, rISOFile.GetName(0).c_str())) SetItem(_Index, COLUMN_TITLE, name, -1); - if (CopySJISToString(description, rISOFile.GetDescription(0).c_str())) + if (WxUtils::CopySJISToString(description, rISOFile.GetDescription(0).c_str())) SetItem(_Index, COLUMN_NOTES, description, -1); m_gameList.append(StringFromFormat("%s (U)\n", (const char*)name.mb_str(wxConvUTF8))); break; @@ -1063,57 +1063,4 @@ void CGameListCtrl::UnselectAll() } -bool CGameListCtrl::CopySJISToString( wxString& _rDestination, const char* _src ) -{ - bool returnCode = false; -#ifdef WIN32 - // HyperIris: because dolphin using "Use Multi-Byte Character Set", - // we must convert the SJIS chars to unicode then to our windows local by hand - u32 unicodeNameSize = MultiByteToWideChar(932, MB_PRECOMPOSED, - _src, (int)strlen(_src), NULL, NULL); - if (unicodeNameSize > 0) - { - u16* pUnicodeStrBuffer = new u16[unicodeNameSize + 1]; - if (pUnicodeStrBuffer) - { - memset(pUnicodeStrBuffer, 0, (unicodeNameSize + 1) * sizeof(u16)); - if (MultiByteToWideChar(932, MB_PRECOMPOSED, - _src, (int)strlen(_src), - (LPWSTR)pUnicodeStrBuffer, unicodeNameSize)) - { - -#ifdef _UNICODE - _rDestination = (LPWSTR)pUnicodeStrBuffer; - returnCode = true; -#else - u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, - NULL, NULL, NULL, NULL); - if (ansiNameSize > 0) - { - char* pAnsiStrBuffer = new char[ansiNameSize + 1]; - if (pAnsiStrBuffer) - { - memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); - if (WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, - pAnsiStrBuffer, ansiNameSize, NULL, NULL)) - { - _rDestination = pAnsiStrBuffer; - returnCode = true; - } - delete pAnsiStrBuffer; - } - } -#endif - } - delete pUnicodeStrBuffer; - } - } -#else - _rDestination = wxString(wxString(_src,wxConvLibc),wxConvUTF8); - returnCode = true; -#endif - return returnCode; -} diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.h b/Source/Core/DolphinWX/Src/GameListCtrl.h index 0000655fd9..b8ee29732c 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.h +++ b/Source/Core/DolphinWX/Src/GameListCtrl.h @@ -98,9 +98,6 @@ private: static size_t m_numberItem; static void CompressCB(const char* text, float percent, void* arg); static void MultiCompressCB(const char* text, float percent, void* arg); - - // hyperiris: put it here will be nice, if we moce to wx unicode, it simple to fix - bool CopySJISToString(wxString& _rDestination, const char* _src); }; diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index b6e3fbeb5f..12f78712b3 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -189,7 +189,7 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW // hyperiris: temp fix, need real work wxString name; - CopySJISToString(name, OpenGameListItem->GetName(0).c_str()); + WxUtils::CopySJISToString(name, OpenGameListItem->GetName(0).c_str()); SetTitle(wxString::Format(wxT("%s%s"), wxString::FromAscii(StringFromFormat("%s%s: %s - ", filename.c_str(), extension.c_str(), OpenGameListItem->GetUniqueID().c_str()).c_str()), @@ -1014,65 +1014,13 @@ void CISOProperties::OnChangeBannerLang(wxCommandEvent& event) void CISOProperties::ChangeBannerDetails(int lang) { - wxString name; - CopySJISToString(name, OpenGameListItem->GetName(lang).c_str()); - wxString description; - CopySJISToString(description, OpenGameListItem->GetDescription(lang).c_str()); + wxString name, + description; + + WxUtils::CopySJISToString(name, OpenGameListItem->GetName(lang).c_str()); + WxUtils::CopySJISToString(description, OpenGameListItem->GetDescription(lang).c_str()); m_ShortName->SetValue(name); m_Maker->SetValue(wxString::FromAscii(OpenGameListItem->GetCompany().c_str()));//dev too m_Comment->SetValue(description); } - -bool CISOProperties::CopySJISToString( wxString& _rDestination, const char* _src ) -{ - bool returnCode = false; -#ifdef WIN32 - // HyperIris: because dolphin using "Use Multi-Byte Character Set", - // we must convert the SJIS chars to unicode then to our windows local by hand - u32 unicodeNameSize = MultiByteToWideChar(932, MB_PRECOMPOSED, - _src, (int)strlen(_src), NULL, NULL); - if (unicodeNameSize > 0) - { - u16* pUnicodeStrBuffer = new u16[unicodeNameSize + 1]; - if (pUnicodeStrBuffer) - { - memset(pUnicodeStrBuffer, 0, (unicodeNameSize + 1) * sizeof(u16)); - if (MultiByteToWideChar(932, MB_PRECOMPOSED, - _src, (int)strlen(_src), - (LPWSTR)pUnicodeStrBuffer, unicodeNameSize)) - { -#ifdef _UNICODE - _rDestination = (LPWSTR)pUnicodeStrBuffer; - returnCode = true; -#else - u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, - NULL, NULL, NULL, NULL); - if (ansiNameSize > 0) - { - char* pAnsiStrBuffer = new char[ansiNameSize + 1]; - if (pAnsiStrBuffer) - { - memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); - if (WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, - pAnsiStrBuffer, ansiNameSize, NULL, NULL)) - { - _rDestination = pAnsiStrBuffer; - returnCode = true; - } - delete pAnsiStrBuffer; - } - } -#endif - } - delete[] pUnicodeStrBuffer; - } - } -#else - _rDestination = wxString(wxString(_src,wxConvLibc),wxConvUTF8); - returnCode = true; -#endif - return returnCode; -} diff --git a/Source/Core/DolphinWX/Src/ISOProperties.h b/Source/Core/DolphinWX/Src/ISOProperties.h index 1e645d4276..1b044c25c8 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.h +++ b/Source/Core/DolphinWX/Src/ISOProperties.h @@ -27,6 +27,7 @@ #include #include #include +#include "WxUtils.h" #include #include "ISOFile.h" @@ -251,8 +252,5 @@ class CISOProperties : public wxDialog void ActionReplayList_Load(); void ActionReplayList_Save(); void ChangeBannerDetails(int lang); - - // HyperIris: duplicate from GameListCtrl, who can merge them and put them in a suitable place? - bool CopySJISToString(wxString& _rDestination, const char* _src); }; #endif diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index 2f12168b75..9c2f21a582 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -18,6 +18,7 @@ #include "MemcardManager.h" #include "Common.h" #include "wx/mstream.h" +#include "WxUtils.h" #define DEFAULTS wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator #define ARROWS slot ? _T("") : ARROW[slot], slot ? ARROW[slot] : _T("") @@ -116,7 +117,7 @@ CMemcardManager::CMemcardManager(wxWindow* parent, wxWindowID id, const wxString } else itemsPerPage = 16; maxPages = (128 / itemsPerPage) - 1; -#ifdef DEBUG_MCM +#ifdef MCM_DEBUG_FRAME MemcardManagerDebug = NULL; #endif CreateGUIControls(); @@ -134,7 +135,7 @@ CMemcardManager::~CMemcardManager() delete memoryCard[SLOT_B]; memoryCard[SLOT_B] = NULL; } -#ifdef DEBUG_MCM +#ifdef MCM_DEBUG_FRAME if (MemcardManagerDebug) { MemcardManagerDebug->Destroy(); @@ -553,7 +554,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) slot = SLOT_A; case ID_SAVEIMPORT_B: { - wxString temp = wxFileSelector(wxT("Select a save file to import"), + wxString fileName = wxFileSelector(wxT("Select a save file to import"), (strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0) ? wxString::FromAscii(""): wxString::FromAscii(DefaultIOPath.c_str()), wxEmptyString, wxEmptyString, wxString::Format ( wxT("Gamecube save files(*.gci,*.gcs,*.sav)|*.gci;*.gcs;*.sav|") @@ -564,8 +565,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) wxFileSelectorDefaultWildcardStr ), wxFD_OPEN | wxFD_FILE_MUST_EXIST); - const char * fileName = temp.mb_str(); - if (!temp.empty() && !fileName2.empty()) + if (!fileName.empty() && !fileName2.empty()) { wxString temp2 = wxFileSelector(wxT("Save GCI as.."), wxEmptyString, wxEmptyString, wxT(".gci"), wxString::Format @@ -578,9 +578,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) if (temp2.empty()) break; fileName2 = temp2.mb_str(); } - if (temp.length() > 0) + if (fileName.length() > 0) { - CopyDeleteSwitch(memoryCard[slot]->ImportGci(fileName, fileName2), slot); + CopyDeleteSwitch(memoryCard[slot]->ImportGci(fileName.mb_str(), fileName2), slot); } } break; @@ -647,14 +647,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) } bool CMemcardManager::ReloadMemcard(const char *fileName, int card) -{ - wxString wxBlock; - wxString wxFirstBlock; - wxString wxLabel; - wxString tString; - - int j; - +{ if (memoryCard[card]) delete memoryCard[card]; // TODO: add error checking and animate icons @@ -662,6 +655,17 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card) if (memoryCard[card]->fail) return false; + int j; + bool ascii = memoryCard[card]->IsAsciiEncoding(); + + wxString wxTitle, + wxComment, + wxBlock, + wxFirstBlock, + wxLabel, + tString; + + m_MemcardList[card]->Hide(); m_MemcardList[card]->ClearAll(); @@ -751,10 +755,23 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card) int index = m_MemcardList[card]->InsertItem(j, wxEmptyString); m_MemcardList[card]->SetItem(index, COLUMN_BANNER, wxEmptyString); + if (!memoryCard[card]->DEntry_Comment1(j, title)) title[0]=0; - m_MemcardList[card]->SetItem(index, COLUMN_TITLE, wxString::FromAscii(title)); if (!memoryCard[card]->DEntry_Comment2(j, comment)) comment[0]=0; - m_MemcardList[card]->SetItem(index, COLUMN_COMMENT, wxString::FromAscii(comment)); + + if (ascii) + { + wxTitle = wxString::FromAscii(title); + wxComment = wxString::FromAscii(comment); + } + else + { + WxUtils::CopySJISToString(wxTitle, title); + WxUtils::CopySJISToString(wxComment, comment); + } + m_MemcardList[card]->SetItem(index, COLUMN_TITLE, wxTitle); + m_MemcardList[card]->SetItem(index, COLUMN_COMMENT, wxComment); + blocks = memoryCard[card]->DEntry_BlockCount(j); if (blocks == 0xFFFF) blocks = 0; wxBlock.Printf(wxT("%10d"), blocks); @@ -847,7 +864,7 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card) t_Status[card]->SetLabel(wxLabel); -#ifdef DEBUG_MCM +#ifdef MCM_DEBUG_FRAME if(MemcardManagerDebug == NULL) { MemcardManagerDebug = new CMemcardManagerDebug((wxFrame *)NULL, wxDefaultPosition, wxSize(950, 400)); diff --git a/Source/Core/DolphinWX/Src/MemcardManager.h b/Source/Core/DolphinWX/Src/MemcardManager.h index baaad7e10a..7cc0c2b573 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.h +++ b/Source/Core/DolphinWX/Src/MemcardManager.h @@ -42,6 +42,7 @@ #undef CONFIG_FILE #define CONFIG_FILE "./MemcardManager.ini" #define DEBUG_MCM +#define MCM_DEBUG_FRAME #include "MCMdebug.h" #endif @@ -64,7 +65,7 @@ class CMemcardManager std::string DefaultMemcard[2], DefaultIOPath; IniFile MemcardManagerIni; -#ifdef DEBUG_MCM +#ifdef MCM_DEBUG_FRAME CMemcardManagerDebug * MemcardManagerDebug; #endif diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp index 0a6d97a642..e5a4f18667 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp @@ -71,7 +71,7 @@ GCMemcard::GCMemcard(const char *filename) fail = false; if (!mcd) { - if (!PanicYesNo("\"%s\" does not exist.\n Create a new 16MB Memcard?", filename)) + if (!AskYesNo("\"%s\" does not exist.\n Create a new 16MB Memcard?", filename)) { fail = true; return; @@ -83,7 +83,7 @@ GCMemcard::GCMemcard(const char *filename) return; } mcdFile = mcd; - Format(); + Format(!AskYesNo("Format as ascii (NTSC\\PAL)?\nChoose no for sjis (NTSC-J)", filename)); fclose(mcd); mcd = fopen(filename, "r+b"); } @@ -232,6 +232,11 @@ bool GCMemcard::IsOpen() return (mcdFile!=NULL); } +bool GCMemcard::IsAsciiEncoding() +{ + return hdr.Encoding[1] == 0; +} + bool GCMemcard::Save() { bool completeWrite = true; @@ -769,17 +774,17 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u8 index) } } -u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2) +u32 GCMemcard::ImportGci(const char *inputFile, std::string outputFile) { - if (fileName2.empty() && !mcdFile) return OPENFAIL; + if (outputFile.empty() && !mcdFile) return OPENFAIL; - FILE *gci = fopen(fileName, "rb"); + FILE *gci = fopen(inputFile, "rb"); if (!gci) return OPENFAIL; int offset; char * tmp = new char[0xD]; std::string fileType; - SplitPath(fileName, NULL, NULL, &fileType); + SplitPath(inputFile, NULL, NULL, &fileType); if( !strcasecmp(fileType.c_str(), ".gci")) offset = GCI; @@ -837,9 +842,9 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2) fread(tempSaveData, 1, size, gci); fclose(gci); u32 ret; - if(!fileName2.empty()) + if(!outputFile.empty()) { - FILE * gci2 = fopen(fileName2.c_str(), "wb"); + FILE * gci2 = fopen(outputFile.c_str(), "wb"); bool completeWrite = true; if (!gci2) return OPENFAIL; fseek(gci2, 0, SEEK_SET); @@ -1132,7 +1137,7 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays) return frames; } -bool GCMemcard::Format(bool New, int slot, u16 SizeMb, bool sjis, bool hdrOnly) +bool GCMemcard::Format(bool sjis, bool New, int slot, u16 SizeMb, bool hdrOnly) { //Currently only formats cards for slot A u32 data_size = BLOCK_SIZE * (SizeMb * MBIT_TO_BLOCKS - MC_FST_BLOCKS); diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h index e38c02effd..a58aa656e0 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h @@ -174,8 +174,9 @@ public: ~GCMemcard(); bool IsOpen(); + bool IsAsciiEncoding(); bool Save(); - bool Format(bool New = true, int slot = 0, u16 SizeMb = MemCard2043Mb, bool sjis = false, bool hdrOnly = false); + bool Format(bool sjis = false, bool New = true, int slot = 0, u16 SizeMb = MemCard2043Mb, bool hdrOnly = false); void calc_checksumsBE(u16 *buf, u32 num, u16 *c1, u16 *c2); u32 TestChecksums(); @@ -238,7 +239,7 @@ public: u32 CopyFrom(GCMemcard& source, u8 index); // reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file - u32 ImportGci(const char* fileName, std::string fileName2); + u32 ImportGci(const char* inputFile, std::string outputFile); // writes a .gci file to disk containing index u32 ExportGci(u8 index, const char* fileName, std::string* fileName2); diff --git a/Source/Core/DolphinWX/Src/WxUtils.cpp b/Source/Core/DolphinWX/Src/WxUtils.cpp index b0594e6d83..34af9c0240 100644 --- a/Source/Core/DolphinWX/Src/WxUtils.cpp +++ b/Source/Core/DolphinWX/Src/WxUtils.cpp @@ -44,5 +44,59 @@ void Explore(const char *path) // WARN_LOG } } - + +bool CopySJISToString(wxString& _rDestination, const char* _src) +{ + bool returnCode = false; +#ifdef WIN32 + // HyperIris: because dolphin using "Use Multi-Byte Character Set", + // we must convert the SJIS chars to unicode then to our windows local by hand + u32 unicodeNameSize = MultiByteToWideChar(932, MB_PRECOMPOSED, + _src, (int)strlen(_src), NULL, NULL); + if (unicodeNameSize > 0) + { + u16* pUnicodeStrBuffer = new u16[unicodeNameSize + 1]; + if (pUnicodeStrBuffer) + { + memset(pUnicodeStrBuffer, 0, (unicodeNameSize + 1) * sizeof(u16)); + if (MultiByteToWideChar(932, MB_PRECOMPOSED, + _src, (int)strlen(_src), + (LPWSTR)pUnicodeStrBuffer, unicodeNameSize)) + { + +#ifdef _UNICODE + _rDestination = (LPWSTR)pUnicodeStrBuffer; + returnCode = true; +#else + u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, + NULL, NULL, NULL, NULL); + if (ansiNameSize > 0) + { + char* pAnsiStrBuffer = new char[ansiNameSize + 1]; + if (pAnsiStrBuffer) + { + memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); + if (WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, + pAnsiStrBuffer, ansiNameSize, NULL, NULL)) + { + _rDestination = pAnsiStrBuffer; + returnCode = true; + } + delete pAnsiStrBuffer; + } + } +#endif + } + delete pUnicodeStrBuffer; + } + } +#else + _rDestination = wxString(wxString(_src,wxConvLibc),wxConvUTF8); + returnCode = true; +#endif + return returnCode; +} + } // namespace diff --git a/Source/Core/DolphinWX/Src/WxUtils.h b/Source/Core/DolphinWX/Src/WxUtils.h index 9c5408726a..f665df81d5 100644 --- a/Source/Core/DolphinWX/Src/WxUtils.h +++ b/Source/Core/DolphinWX/Src/WxUtils.h @@ -25,7 +25,8 @@ void Launch(const char *filename); // Launch an file explorer window on a certain path void Explore(const char *path); - + +bool CopySJISToString(wxString& _rDestination, const char* _src); } // namespace #endif // WXUTILS