[Project64] Change file handling to be ansi

This commit is contained in:
zilmar 2015-11-30 21:14:14 +11:00
parent 832248d818
commit f50f634daf
3 changed files with 216 additions and 209 deletions

View File

@ -130,7 +130,8 @@ stdstr & stdstr::TrimLeft (const char * chars2remove)
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
erase(0, pos); erase(0, pos);
} else { }
else {
erase(begin(), end()); // make empty erase(begin(), end()); // make empty
} }
} }
@ -145,7 +146,8 @@ stdstr & stdstr::TrimRight (const char * chars2remove)
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
erase(pos + 1); erase(pos + 1);
} else { }
else {
erase(begin(), end()); // make empty erase(begin(), end()); // make empty
} }
} }
@ -214,12 +216,12 @@ stdstr & stdstr::FromUTF16 ( const wchar_t * UTF16Source, bool * bSuccess )
return *this; return *this;
} }
std::wstring stdstr::ToUTF16 ( bool * bSuccess) std::wstring stdstr::ToUTF16(UINT CodePage, bool * bSuccess)
{ {
bool bConverted = false; bool bConverted = false;
std::wstring res; std::wstring res;
DWORD nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), NULL, 0); DWORD nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), NULL, 0);
if (nNeeded > 0) if (nNeeded > 0)
{ {
wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t)); wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t));
@ -227,7 +229,7 @@ std::wstring stdstr::ToUTF16 ( bool * bSuccess)
{ {
memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t)); memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t));
nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), buf, nNeeded); nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), buf, nNeeded);
if (nNeeded) if (nNeeded)
{ {
res = buf; res = buf;

View File

@ -13,6 +13,12 @@ class stdstr :
public std::string public std::string
{ {
public: public:
enum
{
CODEPAGE_UTF8 = 65001,
CODEPAGE_932 = 932,
};
stdstr(); stdstr();
stdstr(const std::string & str); stdstr(const std::string & str);
stdstr(const stdstr & str); stdstr(const stdstr & str);
@ -33,10 +39,9 @@ public:
stdstr & TrimRight(const char * chars2remove = "\t "); stdstr & TrimRight(const char * chars2remove = "\t ");
stdstr & FromUTF16(const wchar_t * UTF16Source, bool * bSuccess = NULL); stdstr & FromUTF16(const wchar_t * UTF16Source, bool * bSuccess = NULL);
std::wstring ToUTF16 ( bool * bSuccess = NULL); std::wstring ToUTF16(unsigned int CodePage = CODEPAGE_UTF8, bool * bSuccess = NULL);
void ArgFormat(const char * strFormat, va_list & args); void ArgFormat(const char * strFormat, va_list & args);
}; };
class stdstr_f : public stdstr class stdstr_f : public stdstr

View File

@ -474,7 +474,7 @@ bool CRomBrowser::FillRomInfo(ROM_INFO * pRomInfo)
InternalName[count + 1] ^= InternalName[count + 2]; InternalName[count + 1] ^= InternalName[count + 2];
} }
InternalName[20] = '\0'; InternalName[20] = '\0';
wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16().c_str()); wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
} }
pRomInfo->CartID[0] = *(RomData + 0x3F); pRomInfo->CartID[0] = *(RomData + 0x3F);
pRomInfo->CartID[1] = *(RomData + 0x3E); pRomInfo->CartID[1] = *(RomData + 0x3E);
@ -728,7 +728,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c
InternalName[count + 1] ^= InternalName[count + 2]; InternalName[count + 1] ^= InternalName[count + 2];
} }
InternalName[20] = '\0'; InternalName[20] = '\0';
wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16().c_str()); wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
} }
RomInfo.RomSize = (int32_t)f->Size; RomInfo.RomSize = (int32_t)f->Size;
@ -1431,7 +1431,7 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh)
break; break;
default: wcsncpy(lpdi->item.pszText, L" ", lpdi->item.cchTextMax); default: wcsncpy(lpdi->item.pszText, L" ", lpdi->item.cchTextMax);
} }
if (lpdi->item.pszText == NULL || wcslen(lpdi->item.pszText) == 0) { wcscpy(lpdi->item.pszText, L" "); } if (lpdi->item.pszText == NULL || wcslen(lpdi->item.pszText) == 0) { lpdi->item.pszText = L" "; }
} }
void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/)