CDVD: Remove wxStr from SYSTEM.CNF parsing

This commit is contained in:
Connor McLaughlin 2022-04-12 00:13:49 +10:00 committed by refractionpcsx2
parent 5fa9427323
commit 1bfc0f3138
4 changed files with 77 additions and 28 deletions

View File

@ -24,6 +24,7 @@
#include <wx/datetime.h>
#include "common/FileSystem.h"
#include "common/StringUtil.h"
#include "CdRom.h"
#include "CDVD.h"
@ -465,6 +466,50 @@ static __fi void _reloadPSXElfInfo(wxString elfpath)
// binary).
}
static std::string ExecutablePathToSerial(const std::string& path)
{
// cdrom:\SCES_123.45;1
std::string::size_type pos = path.rfind('\\');
std::string serial;
if (pos != std::string::npos)
{
serial = path.substr(pos + 1);
}
else
{
// cdrom:SCES_123.45;1
pos = serial.rfind(':');
if (pos != std::string::npos)
serial = path.substr(pos + 1);
else
serial = path;
}
// strip off ; or version number
pos = serial.rfind(';');
if (pos != std::string::npos)
serial.erase(pos);
// SCES_123.45 -> SCES-12345
for (std::string::size_type pos = 0; pos < serial.size();)
{
if (serial[pos] == '.')
{
serial.erase(pos, 1);
continue;
}
if (serial[pos] == '_')
serial[pos] = '-';
else
serial[pos] = static_cast<char>(std::toupper(serial[pos]));
pos++;
}
return serial;
}
void cdvdReloadElfInfo(wxString elfoverride)
{
// called from context of executing VM code (recompilers), so we need to trap exceptions
@ -479,7 +524,7 @@ void cdvdReloadElfInfo(wxString elfoverride)
return;
}
wxString elfpath;
std::string elfpath;
u32 discType = GetPS2ElfName(elfpath);
if (discType == 1)
@ -487,11 +532,9 @@ void cdvdReloadElfInfo(wxString elfoverride)
// PCSX2 currently only recognizes *.elf executables in proper PS2 format.
// To support different PSX titles in the console title and for savestates, this code bypasses all the detection,
// simply using the exe name, stripped of problematic characters.
wxString fname = elfpath.AfterLast('\\').BeforeFirst('_');
wxString fname2 = elfpath.AfterLast('_').BeforeFirst('.');
wxString fname3 = elfpath.AfterLast('.').BeforeFirst(';');
DiscSerial = fname + "-" + fname2 + fname3;
_reloadPSXElfInfo(elfpath);
const std::string serial(ExecutablePathToSerial(elfpath));
DiscSerial = StringUtil::UTF8StringToWxString(serial);
_reloadPSXElfInfo(StringUtil::UTF8StringToWxString(elfpath));
return;
}
@ -500,7 +543,7 @@ void cdvdReloadElfInfo(wxString elfoverride)
return;
// Recognized and PS2 (BOOT2). Good job, user.
_reloadElfInfo(elfpath);
_reloadElfInfo(StringUtil::UTF8StringToWxString(elfpath));
}
catch (Exception::FileNotFound& e)
{

View File

@ -16,6 +16,7 @@
#include "PrecompiledHeader.h"
#include "Common.h"
#include "common/FileSystem.h"
#include "common/StringUtil.h"
#include "GS.h" // for sending game crc to mtgs
#include "Elfheader.h"
@ -313,7 +314,7 @@ void ElfObject::loadHeaders()
// 0 - Invalid or unknown disc.
// 1 - PS1 CD
// 2 - PS2 CD
int GetPS2ElfName( wxString& name )
int GetPS2ElfName( std::string& name )
{
int retype = 0;
@ -326,38 +327,43 @@ int GetPS2ElfName( wxString& name )
while( !file.eof() )
{
const wxString original( fromUTF8(file.readLine().c_str()) );
const ParsedAssignmentString parts( original );
const std::string line(file.readLine());
std::string_view key, value;
if (!StringUtil::ParseAssignmentString(line, &key, &value))
continue;
if( parts.lvalue.IsEmpty() && parts.rvalue.IsEmpty() ) continue;
if( parts.rvalue.IsEmpty() && file.getLength() != file.getSeekPos() )
if( value.empty() && file.getLength() != file.getSeekPos() )
{ // Some games have a character on the last line of the file, don't print the error in those cases.
Console.Warning( "(SYSTEM.CNF) Unusual or malformed entry in SYSTEM.CNF ignored:" );
Console.Indent().WriteLn( original );
Console.Indent().WriteLn(line);
continue;
}
if( parts.lvalue == L"BOOT2" )
if( key == "BOOT2" )
{
name = parts.rvalue;
Console.WriteLn( Color_StrongBlue, L"(SYSTEM.CNF) Detected PS2 Disc = " + name );
Console.WriteLn( Color_StrongBlue, "(SYSTEM.CNF) Detected PS2 Disc = %.*s",
static_cast<int>(value.size()), value.data());
name = value;
retype = 2;
}
else if( parts.lvalue == L"BOOT" )
else if( key == "BOOT" )
{
name = parts.rvalue;
Console.WriteLn( Color_StrongBlue, L"(SYSTEM.CNF) Detected PSX/PSone Disc = " + name );
Console.WriteLn( Color_StrongBlue, "(SYSTEM.CNF) Detected PSX/PSone Disc = %.*s",
static_cast<int>(value.size()), value.data());
name = value;
retype = 1;
}
else if( parts.lvalue == L"VMODE" )
else if( key == "VMODE" )
{
Console.WriteLn( Color_Blue, L"(SYSTEM.CNF) Disc region type = " + parts.rvalue );
Console.WriteLn( Color_Blue, "(SYSTEM.CNF) Disc region type = %.*s",
static_cast<int>(value.size()), value.data());
}
else if( parts.lvalue == L"VER" )
else if( key == "VER" )
{
Console.WriteLn( Color_Blue, L"(SYSTEM.CNF) Software version = " + parts.rvalue );
Console.WriteLn( Color_Blue, "(SYSTEM.CNF) Software version = %.*s",
static_cast<int>(value.size()), value.data());
#ifndef PCSX2_CORE
GameInfo::gameVersion = parts.rvalue;
GameInfo::gameVersion = StringUtil::UTF8StringToWxString(value);
#endif
}
}

View File

@ -154,7 +154,7 @@ class ElfObject
//-------------------
extern void loadElfFile(const wxString& filename);
extern int GetPS2ElfName( wxString& dest );
extern int GetPS2ElfName( std::string& dest );
extern u32 ElfCRC;

View File

@ -630,7 +630,7 @@ void __fastcall eeloadHook()
else
cdvdReloadElfInfo();
wxString discelf;
std::string discelf;
int disctype = GetPS2ElfName(discelf);
std::string elfname;
@ -710,7 +710,7 @@ void __fastcall eeloadHook()
else
{
if (disctype == 2)
elftoload = discelf.ToUTF8();
elftoload = discelf;
else
g_SkipBiosHack = false; // We're not fast booting, so disable it (Fixes some weirdness with the BIOS)
}
@ -733,7 +733,7 @@ void __fastcall eeloadHook()
}
}
if (!g_GameStarted && ((disctype == 2 && elfname == discelf.ToStdString()) || disctype == 1))
if (!g_GameStarted && ((disctype == 2 && elfname == discelf) || disctype == 1))
g_GameLoading = true;
}