[Project64] Have RomBrowser store internal data as utf8

This commit is contained in:
zilmar 2016-04-16 19:55:32 +10:00
parent 59a4b1de68
commit 39a1f4f058
4 changed files with 76 additions and 66 deletions

View File

@ -164,7 +164,7 @@ private:
bool m_Visible;
bool m_ShowingRomBrowser;
bool m_AllowSelectionLastRom;
static std::wstring m_UnknownGoodName;
static std::string m_UnknownGoodName;
HBRUSH_MAP m_Brushes;
std::string m_LastRom;
stdstr m_WatchRomDir;

View File

@ -14,7 +14,7 @@
#include <commctrl.h>
#include <shlobj.h>
std::wstring CRomBrowser::m_UnknownGoodName;
std::string CRomBrowser::m_UnknownGoodName;
CRomBrowser::CRomBrowser(HWND & MainWindow, HWND & StatusWindow) :
m_MainWindow(MainWindow),
@ -633,34 +633,34 @@ int32_t CALLBACK CRomBrowser::RomList_CompareItems(uint32_t lParam1, uint32_t lP
ROM_INFO * pRomInfo2 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam2 : lParam1];
int32_t result;
const wchar_t * GoodName1 = NULL, *GoodName2 = NULL;
const char * GoodName1 = NULL, *GoodName2 = NULL;
if (SortFieldInfo->Key == RB_GoodName)
{
GoodName1 = wcscmp(L"#340#", pRomInfo1->GoodName) != 0 ? pRomInfo1->GoodName : m_UnknownGoodName.c_str();
GoodName2 = wcscmp(L"#340#", pRomInfo2->GoodName) != 0 ? pRomInfo2->GoodName : m_UnknownGoodName.c_str();
GoodName1 = strcmp("#340#", pRomInfo1->GoodName) != 0 ? pRomInfo1->GoodName : m_UnknownGoodName.c_str();
GoodName2 = strcmp("#340#", pRomInfo2->GoodName) != 0 ? pRomInfo2->GoodName : m_UnknownGoodName.c_str();
}
switch (SortFieldInfo->Key)
{
case RB_FileName: result = (int32_t)lstrcmpi(pRomInfo1->FileName, pRomInfo2->FileName); break;
case RB_InternalName: result = (int32_t)lstrcmpiW(pRomInfo1->InternalName, pRomInfo2->InternalName); break;
case RB_GoodName: result = (int32_t)lstrcmpiW(GoodName1, GoodName2); break;
case RB_Status: result = (int32_t)lstrcmpiW(pRomInfo1->Status, pRomInfo2->Status); break;
case RB_InternalName: result = (int32_t)lstrcmpi(pRomInfo1->InternalName, pRomInfo2->InternalName); break;
case RB_GoodName: result = (int32_t)lstrcmpi(GoodName1, GoodName2); break;
case RB_Status: result = (int32_t)lstrcmpi(pRomInfo1->Status, pRomInfo2->Status); break;
case RB_RomSize: result = (int32_t)pRomInfo1->RomSize - (int32_t)pRomInfo2->RomSize; break;
case RB_CoreNotes: result = (int32_t)lstrcmpiW(pRomInfo1->CoreNotes, pRomInfo2->CoreNotes); break;
case RB_PluginNotes: result = (int32_t)lstrcmpiW(pRomInfo1->PluginNotes, pRomInfo2->PluginNotes); break;
case RB_UserNotes: result = (int32_t)lstrcmpiW(pRomInfo1->UserNotes, pRomInfo2->UserNotes); break;
case RB_CartridgeID: result = (int32_t)lstrcmpiW(pRomInfo1->CartID, pRomInfo2->CartID); break;
case RB_CoreNotes: result = (int32_t)lstrcmpi(pRomInfo1->CoreNotes, pRomInfo2->CoreNotes); break;
case RB_PluginNotes: result = (int32_t)lstrcmpi(pRomInfo1->PluginNotes, pRomInfo2->PluginNotes); break;
case RB_UserNotes: result = (int32_t)lstrcmpi(pRomInfo1->UserNotes, pRomInfo2->UserNotes); break;
case RB_CartridgeID: result = (int32_t)lstrcmpi(pRomInfo1->CartID, pRomInfo2->CartID); break;
case RB_Manufacturer: result = (int32_t)pRomInfo1->Manufacturer - (int32_t)pRomInfo2->Manufacturer; break;
case RB_Country: result = (int32_t)pRomInfo1->Country - (int32_t)pRomInfo2->Country; break;
case RB_Developer: result = (int32_t)lstrcmpiW(pRomInfo1->Developer, pRomInfo2->Developer); break;
case RB_Developer: result = (int32_t)lstrcmpi(pRomInfo1->Developer, pRomInfo2->Developer); break;
case RB_Crc1: result = (int32_t)pRomInfo1->CRC1 - (int32_t)pRomInfo2->CRC1; break;
case RB_Crc2: result = (int32_t)pRomInfo1->CRC2 - (int32_t)pRomInfo2->CRC2; break;
case RB_CICChip: result = (int32_t)pRomInfo1->CicChip - (int32_t)pRomInfo2->CicChip; break;
case RB_ReleaseDate: result = (int32_t)lstrcmpiW(pRomInfo1->ReleaseDate, pRomInfo2->ReleaseDate); break;
case RB_ReleaseDate: result = (int32_t)lstrcmpi(pRomInfo1->ReleaseDate, pRomInfo2->ReleaseDate); break;
case RB_Players: result = (int32_t)pRomInfo1->Players - (int32_t)pRomInfo2->Players; break;
case RB_ForceFeedback: result = (int32_t)lstrcmpiW(pRomInfo1->ForceFeedback, pRomInfo2->ForceFeedback); break;
case RB_Genre: result = (int32_t)lstrcmpiW(pRomInfo1->Genre, pRomInfo2->Genre); break;
case RB_ForceFeedback: result = (int32_t)lstrcmpi(pRomInfo1->ForceFeedback, pRomInfo2->ForceFeedback); break;
case RB_Genre: result = (int32_t)lstrcmpi(pRomInfo1->Genre, pRomInfo2->Genre); break;
case RB_FileFormat: result = (int32_t)pRomInfo1->FileFormat - (int32_t)pRomInfo2->FileFormat; break;
default: result = 0; break;
}
@ -686,13 +686,13 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh)
switch (m_FieldType[lpdi->item.iSubItem])
{
case RB_FileName: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->FileName).ToUTF16(CP_ACP).c_str(), lpdi->item.cchTextMax); break;
case RB_InternalName: wcsncpy(lpdi->item.pszText, pRomInfo->InternalName, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_GoodName: wcsncpy(lpdi->item.pszText, pRomInfo->GoodName, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_CoreNotes: wcsncpy(lpdi->item.pszText, pRomInfo->CoreNotes, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_PluginNotes: wcsncpy(lpdi->item.pszText, pRomInfo->PluginNotes, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Status: wcsncpy(lpdi->item.pszText, pRomInfo->Status, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_InternalName: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_GoodName: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->GoodName).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_CoreNotes: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->CoreNotes).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_PluginNotes: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->PluginNotes).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Status: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->Status).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_RomSize: swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"%.1f MBit", (float)pRomInfo->RomSize / 0x20000); break;
case RB_CartridgeID: wcsncpy(lpdi->item.pszText, pRomInfo->CartID, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_CartridgeID: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->CartID).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Manufacturer:
switch (pRomInfo->Manufacturer)
{
@ -740,12 +740,12 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh)
swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"CIC-NUS-610%d", pRomInfo->CicChip);
}
break;
case RB_UserNotes: wcsncpy(lpdi->item.pszText, pRomInfo->UserNotes, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Developer: wcsncpy(lpdi->item.pszText, pRomInfo->Developer, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_ReleaseDate: wcsncpy(lpdi->item.pszText, pRomInfo->ReleaseDate, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Genre: wcsncpy(lpdi->item.pszText, pRomInfo->Genre, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_UserNotes: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->UserNotes).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Developer: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->Developer).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_ReleaseDate: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->ReleaseDate).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Genre: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->Genre).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_Players: swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"%d", pRomInfo->Players); break;
case RB_ForceFeedback: wcsncpy(lpdi->item.pszText, pRomInfo->ForceFeedback, lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_ForceFeedback: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->ForceFeedback).ToUTF16().c_str(), lpdi->item.cchTextMax / sizeof(wchar_t)); break;
case RB_FileFormat:
switch (pRomInfo->FileFormat)
{
@ -869,7 +869,7 @@ void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/)
void CRomBrowser::RomList_SortList(void)
{
SORT_FIELD SortFieldInfo;
m_UnknownGoodName = wGS(RB_NOT_GOOD_FILE);
m_UnknownGoodName = stdstr().FromUTF16(wGS(RB_NOT_GOOD_FILE).c_str());
for (int32_t count = NoOfSortKeys; count >= 0; count--)
{

View File

@ -9,6 +9,13 @@
* *
****************************************************************************/
#include "stdafx.h"
#include "RomList.h"
#include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/N64RomClass.h>
#ifdef _WIN32
#include <Project64-core/3rdParty/7zip.h>
#endif
static const char* ROM_extensions[] =
{
@ -285,7 +292,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory)
char InternalName[22];
memcpy(InternalName, (void *)(RomData + 0x20), 20);
CN64Rom::CleanRomName(InternalName);
wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
strcpy(RomInfo.InternalName, InternalName);
}
RomInfo.RomSize = (int32_t)f->Size;
@ -438,7 +445,7 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo)
char InternalName[22];
memcpy(InternalName, (void *)(RomData + 0x20), 20);
CN64Rom::CleanRomName(InternalName);
wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
strcpy(pRomInfo->InternalName, InternalName);
pRomInfo->CartID[0] = *(RomData + 0x3F);
pRomInfo->CartID[1] = *(RomData + 0x3E);
pRomInfo->CartID[2] = '\0';
@ -456,45 +463,45 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo)
void CRomList::FillRomExtensionInfo(ROM_INFO * pRomInfo)
{
//Initialize the structure
pRomInfo->UserNotes[0] = 0;
pRomInfo->Developer[0] = 0;
pRomInfo->ReleaseDate[0] = 0;
pRomInfo->Genre[0] = 0;
pRomInfo->UserNotes[0] = '\0';
pRomInfo->Developer[0] = '\0';
pRomInfo->ReleaseDate[0] = '\0';
pRomInfo->Genre[0] = '\0';
pRomInfo->Players = 1;
pRomInfo->CoreNotes[0] = 0;
pRomInfo->PluginNotes[0] = 0;
wcscpy(pRomInfo->GoodName, L"#340#");
wcscpy(pRomInfo->Status, L"Unknown");
pRomInfo->CoreNotes[0] = '\0';
pRomInfo->PluginNotes[0] = '\0';
strcpy(pRomInfo->GoodName, "#340#");
strcpy(pRomInfo->Status, "Unknown");
//Get File Identifier
char Identifier[100];
sprintf(Identifier, "%08X-%08X-C:%X", pRomInfo->CRC1, pRomInfo->CRC2, pRomInfo->Country);
//Rom Notes
wcsncpy(pRomInfo->UserNotes, m_NotesIniFile->GetString(Identifier, "Note", "").ToUTF16().c_str(), sizeof(pRomInfo->UserNotes) / sizeof(wchar_t));
strncpy(pRomInfo->UserNotes, m_NotesIniFile->GetString(Identifier, "Note", "").c_str(), sizeof(pRomInfo->UserNotes) / sizeof(char));
//Rom Extension info
wcsncpy(pRomInfo->Developer, m_ExtIniFile->GetString(Identifier, "Developer", "").ToUTF16().c_str(), sizeof(pRomInfo->Developer) / sizeof(wchar_t));
wcsncpy(pRomInfo->ReleaseDate, m_ExtIniFile->GetString(Identifier, "ReleaseDate", "").ToUTF16().c_str(), sizeof(pRomInfo->ReleaseDate) / sizeof(wchar_t));
wcsncpy(pRomInfo->Genre, m_ExtIniFile->GetString(Identifier, "Genre", "").ToUTF16().c_str(), sizeof(pRomInfo->Genre) / sizeof(wchar_t));
strncpy(pRomInfo->Developer, m_ExtIniFile->GetString(Identifier, "Developer", "").c_str(), sizeof(pRomInfo->Developer) / sizeof(char));
strncpy(pRomInfo->ReleaseDate, m_ExtIniFile->GetString(Identifier, "ReleaseDate", "").c_str(), sizeof(pRomInfo->ReleaseDate) / sizeof(char));
strncpy(pRomInfo->Genre, m_ExtIniFile->GetString(Identifier, "Genre", "").c_str(), sizeof(pRomInfo->Genre) / sizeof(char));
m_ExtIniFile->GetNumber(Identifier, "Players", 1, (uint32_t &)pRomInfo->Players);
wcsncpy(pRomInfo->ForceFeedback, m_ExtIniFile->GetString(Identifier, "ForceFeedback", "unknown").ToUTF16().c_str(), sizeof(pRomInfo->ForceFeedback) / sizeof(wchar_t));
strncpy(pRomInfo->ForceFeedback, m_ExtIniFile->GetString(Identifier, "ForceFeedback", "unknown").c_str(), sizeof(pRomInfo->ForceFeedback) / sizeof(char));
//Rom Settings
wcsncpy(pRomInfo->GoodName, m_RomIniFile->GetString(Identifier, "Good Name", stdstr().FromUTF16(pRomInfo->GoodName).c_str()).ToUTF16().c_str(), sizeof(pRomInfo->GoodName) / sizeof(wchar_t));
wcsncpy(pRomInfo->Status, m_RomIniFile->GetString(Identifier, "Status", stdstr().FromUTF16(pRomInfo->Status).c_str()).ToUTF16().c_str(), sizeof(pRomInfo->Status) / sizeof(wchar_t));
wcsncpy(pRomInfo->CoreNotes, m_RomIniFile->GetString(Identifier, "Core Note", "").ToUTF16().c_str(), sizeof(pRomInfo->CoreNotes) / sizeof(wchar_t));
wcsncpy(pRomInfo->PluginNotes, m_RomIniFile->GetString(Identifier, "Plugin Note", "").ToUTF16().c_str(), sizeof(pRomInfo->PluginNotes) / sizeof(wchar_t));
strncpy(pRomInfo->GoodName, m_RomIniFile->GetString(Identifier, "Good Name", pRomInfo->GoodName).c_str(), sizeof(pRomInfo->GoodName) / sizeof(char));
strncpy(pRomInfo->Status, m_RomIniFile->GetString(Identifier, "Status", pRomInfo->Status).c_str(), sizeof(pRomInfo->Status) / sizeof(char));
strncpy(pRomInfo->CoreNotes, m_RomIniFile->GetString(Identifier, "Core Note", "").c_str(), sizeof(pRomInfo->CoreNotes) / sizeof(char));
strncpy(pRomInfo->PluginNotes, m_RomIniFile->GetString(Identifier, "Plugin Note", "").c_str(), sizeof(pRomInfo->PluginNotes) / sizeof(char));
//Get the text color
stdstr String = m_RomIniFile->GetString("Rom Status", stdstr().FromUTF16(pRomInfo->Status).c_str(), "000000");
pRomInfo->TextColor = (std::strtoul(String.c_str(), 0, 16) & 0xFFFFFF);
stdstr String = m_RomIniFile->GetString("Rom Status", pRomInfo->Status, "000000");
pRomInfo->TextColor = (strtoul(String.c_str(), 0, 16) & 0xFFFFFF);
pRomInfo->TextColor = (pRomInfo->TextColor & 0x00FF00) | ((pRomInfo->TextColor >> 0x10) & 0xFF) | ((pRomInfo->TextColor & 0xFF) << 0x10);
//Get the selected color
String.Format("%ws.Sel", pRomInfo->Status);
String.Format("%s.Sel", pRomInfo->Status);
String = m_RomIniFile->GetString("Rom Status", String.c_str(), "FFFFFFFF");
uint32_t selcol = std::strtoul(String.c_str(), NULL, 16);
uint32_t selcol = strtoul(String.c_str(), NULL, 16);
if (selcol & 0x80000000)
{
pRomInfo->SelColor = -1;
@ -506,9 +513,9 @@ void CRomList::FillRomExtensionInfo(ROM_INFO * pRomInfo)
}
//Get the selected text color
String.Format("%ws.Seltext", pRomInfo->Status);
String.Format("%s.Seltext", pRomInfo->Status);
String = m_RomIniFile->GetString("Rom Status", String.c_str(), "FFFFFF");
pRomInfo->SelTextColor = (std::strtoul(String.c_str(), 0, 16) & 0xFFFFFF);
pRomInfo->SelTextColor = (strtoul(String.c_str(), 0, 16) & 0xFFFFFF);
pRomInfo->SelTextColor = (pRomInfo->SelTextColor & 0x00FF00) | ((pRomInfo->SelTextColor >> 0x10) & 0xFF) | ((pRomInfo->SelTextColor & 0xFF) << 0x10);
}

View File

@ -9,6 +9,10 @@
* *
****************************************************************************/
#pragma once
#include <Common/path.h>
#include <Common/IniFileClass.h>
#include <Common/md5.h>
#include <Project64-core/N64System/N64Types.h>
class CRomList
{
@ -24,17 +28,17 @@ public:
{
char szFullFileName[300];
FILE_FORMAT FileFormat;
wchar_t Status[60];
char Status[60];
char FileName[200];
wchar_t InternalName[22];
wchar_t GoodName[200];
wchar_t CartID[3];
wchar_t PluginNotes[250];
wchar_t CoreNotes[250];
wchar_t UserNotes[250];
wchar_t Developer[30];
wchar_t ReleaseDate[30];
wchar_t Genre[15];
char InternalName[22];
char GoodName[200];
char CartID[3];
char PluginNotes[250];
char CoreNotes[250];
char UserNotes[250];
char Developer[30];
char ReleaseDate[30];
char Genre[15];
int32_t Players;
uint32_t TextColor;
int32_t SelColor;
@ -44,8 +48,8 @@ public:
uint8_t Country;
uint32_t CRC1;
uint32_t CRC2;
int32_t CicChip;
wchar_t ForceFeedback[15];
CICChip CicChip;
char ForceFeedback[15];
};
CRomList();
@ -60,7 +64,6 @@ protected:
virtual void RomListReset(void) {}
virtual void RomAddedToList(int32_t /*ListPos*/) {}
virtual void RomListLoaded(void) {}
virtual void RomDirChanged(void) {}
MD5 RomListHash(strlist & FileList);
void AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File);