pcsx2: Improve GameDB multiline section parsing

If the entry separator (line of dashes) is found, assume the multiline
section end tag is missing or incorrect and stop parsing so that it
doesn't affect subsequent database entries.

Also improve the error messages so it is slightly more clear what the
error is.
This commit is contained in:
Jonathan Li 2018-09-06 01:49:28 +01:00
parent 8acc319a4a
commit f47321c287
1 changed files with 11 additions and 6 deletions

View File

@ -45,13 +45,13 @@ public:
void ReadGames(); void ReadGames();
protected: protected:
void doError(bool doMsg = false); void doError(const wxString& msg);
bool extractMultiLine(); bool extractMultiLine();
void extract(); void extract();
}; };
void DBLoaderHelper::doError(bool doMsg) { void DBLoaderHelper::doError(const wxString& msg) {
if (doMsg) Console.Error(L"GameDatabase: Bad file data [%s]", WX_STR(m_dest)); Console.Error(msg);
m_keyPair.Clear(); m_keyPair.Clear();
} }
@ -68,7 +68,7 @@ bool DBLoaderHelper::extractMultiLine() {
if (m_dest[0] != L'[') return false; // All multiline sections begin with a '['! if (m_dest[0] != L'[') return false; // All multiline sections begin with a '['!
if (!m_dest.EndsWith(L"]")) { if (!m_dest.EndsWith(L"]")) {
doError(true); doError("GameDatabase: Malformed section start tag: " + m_dest);
return false; return false;
} }
@ -84,16 +84,21 @@ bool DBLoaderHelper::extractMultiLine() {
while(!m_reader.Eof()) { while(!m_reader.Eof()) {
pxReadLine( m_reader, m_dest, m_intermediate ); pxReadLine( m_reader, m_dest, m_intermediate );
if (m_dest.CmpNoCase(endString) == 0) break; // Abort if the closing tag is missing/incorrect so subsequent database entries aren't affected.
if (m_dest == "---------------------------------------------")
break;
if (m_dest.CmpNoCase(endString) == 0)
return true;
m_keyPair.value += m_dest + L"\n"; m_keyPair.value += m_dest + L"\n";
} }
doError("GameDatabase: Missing or incorrect section end tag:\n" + m_keyPair.key + "\n" + m_keyPair.value);
return true; return true;
} }
void DBLoaderHelper::extract() { void DBLoaderHelper::extract() {
if( !pxParseAssignmentString( m_dest, m_keyPair.key, m_keyPair.value ) ) return; if( !pxParseAssignmentString( m_dest, m_keyPair.key, m_keyPair.value ) ) return;
if( m_keyPair.value.IsEmpty() ) doError(true); if( m_keyPair.value.IsEmpty() ) doError("GameDatabase: Bad file data: " + m_dest);
} }
void DBLoaderHelper::ReadGames() void DBLoaderHelper::ReadGames()