Converted the GameDB to use wxWidgets classes.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3188 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-06-09 17:37:11 +00:00
parent 00404edfbc
commit ff1db14f9d
21 changed files with 360 additions and 429 deletions

View File

@ -271,6 +271,10 @@
RelativePath="..\..\src\Utilities\pxStaticText.cpp"
>
</File>
<File
RelativePath="..\..\src\Utilities\pxTextStream.cpp"
>
</File>
<File
RelativePath="..\..\src\Utilities\pxWindowTextWriter.cpp"
>

View File

@ -17,6 +17,14 @@
// Dependencies.h : Contains classes required by all Utilities headers.
// --------------------------------------------------------------------------------------
// Forward Declarations Section
// --------------------------------------------------------------------------------------
class wxOutputStream;
class wxInputStream;
// This should prove useful....
#define wxsFormat wxString::Format

View File

@ -65,6 +65,8 @@ struct ParsedAssignmentString
ParsedAssignmentString( const wxString& src );
};
extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest );
extern wxString FastFormatString_Ascii(const char* fmt, va_list argptr);
extern wxString FastFormatString_Unicode(const wxChar* fmt, va_list argptr);

View File

@ -15,7 +15,6 @@
#pragma once
#include <wx/wx.h>
#include "wxGuiTools.h"
// --------------------------------------------------------------------------------------

View File

@ -50,13 +50,23 @@ protected:
bool m_prev;
public:
wxDoNotLogInThisScope() :
m_prev( wxLog::EnableLogging( false ) )
wxDoNotLogInThisScope()
{
m_prev = wxLog::EnableLogging( false );
}
~wxDoNotLogInThisScope()
virtual ~wxDoNotLogInThisScope() throw()
{
wxLog::EnableLogging( m_prev );
}
};
extern wxString pxReadLine( wxInputStream& input );
extern void pxReadLine( wxInputStream& input, wxString& dest );
extern void pxReadLine( wxInputStream& input, wxString& dest, std::string& intermed );
extern bool pxReadLine( wxInputStream& input, std::string& dest );
extern void pxWriteLine( wxOutputStream& output );
extern void pxWriteLine( wxOutputStream& output, const wxString& text );
extern void pxWriteMultiline( wxOutputStream& output, const wxString& src );

View File

@ -807,6 +807,9 @@ extern bool pxDialogExists( const wxString& name );
extern bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos );
extern wxRect wxGetDisplayArea();
extern int pxGetCharHeight( const wxWindow* wind, int rows=1 );
extern int pxGetCharHeight( const wxWindow& wind, int rows=1 );
extern wxString pxFormatToolTipText( wxWindow* wind, const wxString& src );
extern void pxSetToolTip( wxWindow* wind, const wxString& src );
extern void pxSetToolTip( wxWindow& wind, const wxString& src );

View File

@ -229,7 +229,7 @@ const wxString& ConsoleBuffer_Get()
void ConsoleBuffer_Clear()
{
ScopedLock lock( m_bufferlock );
m_buffer.Clear();
m_buffer.clear();
}
// Flushes the contents of the ConsoleBuffer to the specified destination file stream, and
@ -239,7 +239,7 @@ void ConsoleBuffer_FlushToFile( FILE *fp )
ScopedLock lock( m_bufferlock );
if( fp == NULL || m_buffer.IsEmpty() ) return;
px_fputs( fp, m_buffer.ToUTF8() );
m_buffer.Clear();
m_buffer.clear();
}
static void __concall ConsoleBuffer_DoWrite( const wxString& fmt )
@ -276,7 +276,7 @@ static void __concall Console_wxLogError_DoWriteLn( const wxString& fmt )
if( !m_buffer.IsEmpty() )
{
wxLogError( m_buffer );
m_buffer.Clear();
m_buffer.clear();
}
wxLogError( fmt );
}
@ -309,12 +309,9 @@ wxString IConsoleWriter::_addIndentation( const wxString& src, int glob_indent=0
const int indent = glob_indent + _imm_indentation;
if( indent == 0 ) return src;
wxArrayString pieces;
SplitString( pieces, src, L'\n' );
wxString result( src );
const wxString indentStr( L'\t', indent );
wxString result;
result.reserve( src.Length() + 24 );
JoinString( result, pieces, L'\n' + indentStr );
result.Replace( L"\n", L"\n" + indentStr );
return indentStr + result;
}

View File

@ -181,17 +181,21 @@ bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval, const wx
return true;
}
// returns TRUE if the parse is valid, or FALSE if it's a comment.
bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest )
{
if( src.StartsWith(L"--") || src.StartsWith( L"//" ) || src.StartsWith( L";" ) )
return false;
ldest = src.BeforeFirst(L'=').Trim(true).Trim(false);
rdest = src.AfterFirst(L'=').Trim(true).Trim(false);
return true;
}
ParsedAssignmentString::ParsedAssignmentString( const wxString& src )
{
IsComment = false;
if( src.StartsWith( L"//" ) || src.StartsWith( L";" ) )
{
IsComment = true;
return;
}
lvalue = src.BeforeFirst(L'=').Trim(true).Trim(false);
rvalue = src.AfterFirst(L'=').Trim(true).Trim(false);
IsComment = pxParseAssignmentString( src, lvalue, rvalue );
}
// Performs a cross-platform puts operation, which adds CRs to naked LFs on Win32 platforms,

View File

@ -79,9 +79,7 @@ pxStaticText& pxStaticText::SetHeight( int lines )
if( !pxAssert(lines > 0) ) lines = 2;
m_heightInLines = lines;
int width, height;
GetTextExtent( _("MyjS 23"), &width, &height );
const int newHeight = ((height+1)*m_heightInLines) + (m_paddingPix_vert*2);
const int newHeight = (pxGetCharHeight(this)*m_heightInLines) + (m_paddingPix_vert*2);
SetMinSize( wxSize(GetMinWidth(), newHeight) );
return *this;

View File

@ -0,0 +1,98 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "wxBaseTools.h"
#include <wx/stream.h>
// Returns TRUE if the source is UTF8, or FALSE if it's just ASCII crap.
bool pxReadLine( wxInputStream& input, std::string& dest )
{
dest.clear();
bool isUTF8 = false;
while ( true )
{
char c;
input.Read(&c, sizeof(c));
if( c == 0 ) break;
if( input.Eof() ) break;
if( c == '\n' ) break; // eat on UNIX
if( c == '\r' )
{
input.Read(&c, sizeof(c));
if( c == 0 ) break;
if( input.Eof() ) break;
if( c == '\n' ) break;
input.Ungetch(c);
break;
}
dest += c;
if( c & 0x80 ) isUTF8 = true;
}
return isUTF8;
}
void pxReadLine( wxInputStream& input, wxString& dest, std::string& intermed )
{
dest.clear();
if( pxReadLine( input, intermed ) )
dest = fromUTF8(intermed.c_str());
else
{
// Optimized ToAscii conversion.
// wx3.0 : NOT COMPATIBLE!! (on linux anyway)
const char* ascii = intermed.c_str();
while( *ascii != 0 ) dest += (wchar_t)(unsigned char)*ascii++;
}
}
void pxReadLine( wxInputStream& input, wxString& dest )
{
std::string line;
pxReadLine( input, dest, line );
}
wxString pxReadLine( wxInputStream& input )
{
wxString result;
pxReadLine( input, result );
return result;
}
void pxWriteLine( wxOutputStream& output )
{
output.Write( "\n", 1 );
}
void pxWriteLine( wxOutputStream& output, const wxString& text )
{
if( !text.IsEmpty() )
output.Write(text.ToUTF8(), text.Length());
pxWriteLine( output );
}
void pxWriteMultiline( wxOutputStream& output, const wxString& src )
{
if( src.IsEmpty() ) return;
wxString result( src );
result.Replace( L"\r\n", L"\n" );
result.Replace( L"\r", wxEmptyString );
output.Write(result.ToUTF8(), result.Length());
}

View File

@ -372,7 +372,7 @@ wxDialogWithHelpers& wxDialogWithHelpers::SetMinHeight( int newHeight )
int wxDialogWithHelpers::GetCharHeight() const
{
return wxClientDC( const_cast<wxDialogWithHelpers*>(this) ).GetCharHeight();
return pxGetCharHeight( this, 1 );
}
// --------------------------------------------------------------------------------------
@ -450,3 +450,16 @@ wxPanelWithHelpers& wxPanelWithHelpers::SetMinWidth( int newWidth )
sizer->SetMinSize( wxSize( newWidth, sizer->GetMinSize().GetHeight() ) );
return *this;
}
int pxGetCharHeight( const wxWindow* wind, int rows )
{
if( !wind ) return 0;
wxClientDC dc(wx_const_cast(wxWindow*, wind));
dc.SetFont( wind->GetFont() );
return (dc.GetCharHeight() + 1 ) * rows;
}
int pxGetCharHeight( const wxWindow& wind, int rows )
{
return pxGetCharHeight( &wind, rows );
}

View File

@ -361,7 +361,7 @@ static __forceinline void _reloadElfInfo(wxString elfpath)
if (DiscID.IsEmpty()) { // Search for crc if no Serial Code
gameSerial = wxString(wxsFormat( L"%8.8x", ElfCRC ));
}
if (GameDB->setGame(gameSerial.ToUTF8().data())) { // Game Found
if (GameDB->setGame(gameSerial)) { // Game Found
Console.WriteLn ("Game = %s (%s)", GameDB->getString("Name").c_str(), GameDB->getString("Region").c_str());
}
else Console.Warning(L"Game not found in database [%s]", gameSerial.c_str());

View File

@ -6,92 +6,51 @@
// DataBase_Loader - Private Methods
//------------------------------------------------------------------
//Fix me
#ifndef __LINUX__
template<class T> string DataBase_Loader::toString(const T& value) {
stringstream ss(ios_base::in | ios_base::out);
string tString;
ss << value;
ss >> tString;
return tString;
}
#endif
string DataBase_Loader::toLower(const string& s) {
string retval( s );
for (uint i = 0; i < s.length(); i++) {
char& c = retval[i];
if (c >= 'A' && c <= 'Z') {
c += 'a' - 'A';
}
}
return retval;
}
bool DataBase_Loader::strCompare(const string& s1, const string& s2) {
const string t1( toLower(s1) );
const string t2( toLower(s2) );
return !t1.compare(t2);
}
bool DataBase_Loader::isComment(const string& s) {
const string sub( s.substr(0, 2) );
return (sub.compare("--") == 0) || (sub.compare("//") == 0);
}
void DataBase_Loader::doError(const string& line, key_pair& keyPair, bool doMsg) {
void DataBase_Loader::doError(const wxString& line, key_pair& keyPair, bool doMsg) {
if (doMsg) Console.Error("DataBase_Loader: Bad file data [%s]", line.c_str());
keyPair.key.clear();
}
void DataBase_Loader::extractMultiLine(const string& line, key_pair& keyPair, File_Reader& reader, const stringstream& ss) {
string t;
string endString;
endString = "[/" + keyPair.key.substr(1, keyPair.key.length()-1);
if (keyPair.key[keyPair.key.length()-1] != ']') {
endString += "]";
keyPair.key = line;
// Multiline Sections are in the form of:
//
// [section=value]
// content
// content
// [/section]
//
// ... where the =value part is OPTIONAL.
void DataBase_Loader::extractMultiLine(key_pair& keyPair, wxInputStream& ffile) {
if (!keyPair.key.EndsWith(L"]")) {
doError(keyPair.key, keyPair, true);
return;
}
// Use Mid() to strip off the left and right side brackets.
ParsedAssignmentString set( keyPair.key.Mid(1, keyPair.key.Length()-2) );
wxString endString;
endString.Printf( L"[/%s]", set.lvalue.c_str() );
for(;;) {
t = reader.getLine();
if (!t.compare(endString)) break;
keyPair.value += t + "\n";
pxReadLine( ffile, m_dest, m_intermediate );
if (m_dest == endString) break;
keyPair.value += m_dest + L"\n";
}
}
void DataBase_Loader::extract(const string& line, key_pair& keyPair, File_Reader& reader) {
stringstream ss(line);
string t;
keyPair.key.clear();
void DataBase_Loader::extract(const wxString& line, key_pair& keyPair, wxInputStream& reader) {
keyPair.key = line;
keyPair.value.clear();
ss >> keyPair.key;
if (!line.length() || isComment(keyPair.key)) {
doError(line, keyPair);
return;
}
if (keyPair.key[0] == '[') {
extractMultiLine(line, keyPair, reader, ss);
if( line.IsEmpty() ) return;
if (keyPair.key[0] == L'[') {
extractMultiLine(keyPair, reader);
return;
}
ss >> t;
if (t.compare("=") != 0) {
if( !pxParseAssignmentString( line, keyPair.key, keyPair.value ) ) return;
if( keyPair.value.IsEmpty() )
doError(line, keyPair, true);
return;
}
ss >> t;
if (isComment(t)) {
doError(line, keyPair, true);
return;
}
keyPair.value = t;
while (!ss.eof() && !ss.fail()) {
ss >> t;
if (isComment(t)) break;
keyPair.value += " " + t;
}
if (ss.fail()) {
doError(line, keyPair);
return;
}
}

View File

@ -18,44 +18,36 @@
#include "Common.h"
#include "File_Reader.h"
#include "AppConfig.h"
#include <wx\wfstream.h>
struct key_pair {
string key;
string value;
wxString key;
wxString value;
key_pair() {}
key_pair(const string& _key, const string& _value)
key_pair(const wxString& _key, const wxString& _value)
: key(_key) , value(_value) {}
string toString() {
string t;
wxString toString() const {
if (key[0] == '[') {
t = key + "\n";
t += value;
stringstream ss(key);
string t2;
ss >> t2;
if (t[t.length()-1] != '\n') t += "\n";
t += "[/" + t2.substr(1, t2.length()-1);
if (t2.compare(key)) t += "]";
pxAssumeDev( key.EndsWith(L"]"), "Malformed multiline key detected: missing end bracket!" );
return wxsFormat( L"%s\n%s\n[/%s\n",
key.c_str(), value.c_str(), key.Mid(1, key.length()-1).c_str()
);
}
else {
t = key;
for (int a = 6 - key.length(); a > 0; a--) {
t += " "; // Padding for nice formatting on small key-names
}
t += " = " + value;
// Note: 6 char padding on the l-value makes things look nicer.
return wxsFormat(L"%-6s = %s\n", key.c_str(), value.c_str() );
}
return t;
}
};
class Game_Data {
public:
string id; // Serial Identification Code
deque<key_pair> kList; // List of all (key, value) pairs for game data
Game_Data(const string& _id)
wxString id; // Serial Identification Code
deque<key_pair> kList; // List of all (key, value) pairs for game data
Game_Data(const wxString& _id)
: id(_id) {}
};
@ -75,57 +67,49 @@ public:
// Such as dbLoader.getString("Region") returns "NTSC-U"
class DataBase_Loader {
private:
// Fix me
#ifdef __LINUX__
template<class T> string toString(const T& value) {
stringstream ss(ios_base::in | ios_base::out);
string tString;
ss << value;
ss >> tString;
return tString;
}
#else
template<class T> string toString(const T& value);
#endif
string toLower(const string& s);
bool strCompare(const string& s1, const string& s2);
bool isComment(const string& s);
void doError(const string& line, key_pair& keyPair, bool doMsg = false);
void extractMultiLine(const string& line, key_pair& keyPair, File_Reader& reader, const stringstream& ss);
void extract(const string& line, key_pair& keyPair, File_Reader& reader);
protected:
bool isComment(const wxString& s);
void doError(const wxString& line, key_pair& keyPair, bool doMsg = false);
void extractMultiLine(key_pair& keyPair, wxInputStream& reader);
void extract(const wxString& line, key_pair& keyPair, wxInputStream& reader);
const wxString m_emptyString; // empty string for returning stuff .. never modify!
wxString m_dest;
std::string m_intermediate;
public:
deque<Game_Data*> gList; // List of all game data
Game_Data* curGame; // Current game data
String_Stream header; // Header of the database
string baseKey; // Key to separate games by ("Serial")
deque<Game_Data*> gList; // List of all game data
Game_Data* curGame; // Current game data
wxString header; // Header of the database
wxString baseKey; // Key to separate games by ("Serial")
DataBase_Loader(const string& file = "GameIndex.dbf", const string& key = "Serial", const string& value = "" ) {
DataBase_Loader(const wxString& file = L"GameIndex.dbf", const wxString& key = L"Serial", const wxString& value = wxEmptyString )
: baseKey( key )
{
curGame = NULL;
baseKey = key;
if (!fileExists(file)) {
Console.Error("DataBase_Loader: DataBase Not Found! [%s]", file.c_str());
if (!wxFileExists(file)) {
Console.Error(L"DataBase_Loader: DataBase Not Found! [%s]", file.c_str());
}
File_Reader reader(file);
wxFFileInputStream reader( file );
key_pair keyPair;
string s0;
wxString s0;
Game_Data* game = NULL;
try {
for(;;) {
for(;;) { // Find first game
s0 = reader.getLine();
extract(s0, keyPair, reader);
if (keyPair.key.compare(key) == 0) break;
header.write(s0);
header.write("\n");
while(!reader.Eof()) {
while(!reader.Eof()) { // Find first game
pxReadLine(reader, s0, m_intermediate);
extract(s0.Trim(true).Trim(false), keyPair, reader);
if (keyPair.key == key) break;
header += s0 + L'\n';
}
game = new Game_Data(keyPair.value);
game->kList.push_back(keyPair);
for (;;) { // Fill game data, find new game, repeat...
s0 = reader.getLine();
extract(s0, keyPair, reader);
if (keyPair.key.compare("") == 0) continue;
if (keyPair.key.compare(key) == 0) {
while(!reader.Eof()) { // Fill game data, find new game, repeat...
pxReadLine(reader, s0, m_intermediate);
extract(s0.Trim(true).Trim(false), keyPair, reader);
if (keyPair.key.IsEmpty()) continue;
if (keyPair.key == key) {
gList.push_back(game);
game = new Game_Data(keyPair.value);
}
@ -133,27 +117,25 @@ public:
}
}
}
catch(int& i) { // Add Last Game if EOF
if (i==1 && game) gList.push_back(game);
}
if (!value.compare("")) return;
if (setGame(value)) Console.WriteLn("DataBase_Loader: Found Game! [%s]", value.c_str());
else Console.Warning("DataBase_Loader: Game Not Found! [%s]", value.c_str());
catch( Exception::EndOfStream& ) {}
if (game) gList.push_back(game);
if (value.IsEmpty()) return;
if (setGame(value)) Console.WriteLn(L"DataBase_Loader: Found Game! [%s]", value.c_str());
else Console.Warning(L"DataBase_Loader: Game Not Found! [%s]", value.c_str());
}
virtual ~DataBase_Loader() throw() {
deque<Game_Data*>::iterator it = gList.begin();
for ( ; it != gList.end(); ++it) {
delete *it;
}
// deque deletes its contents automatically.
}
// Sets the current game to the one matching the serial id given
// Returns true if game found, false if not found...
bool setGame(const string& id) {
bool setGame(const wxString& id) {
deque<Game_Data*>::iterator it = gList.begin();
for ( ; it != gList.end(); ++it) {
if (strCompare(it[0]->id, id)) {
if (it[0]->id == id) {
curGame = it[0];
return true;
}
@ -170,22 +152,22 @@ public:
}
// Saves changes to the database
void saveToFile(const string& file = "GameIndex.dbf") {
File_Writer writer(file);
writer.write(header.toString());
void saveToFile(const wxString& file = L"GameIndex.dbf") {
wxFFileOutputStream writer( file );
pxWriteMultiline(writer, header);
deque<Game_Data*>::iterator it = gList.begin();
for ( ; it != gList.end(); ++it) {
deque<key_pair>::iterator i = it[0]->kList.begin();
for ( ; i != it[0]->kList.end(); ++i) {
writer.write(i[0].toString() + "\n");
pxWriteMultiline(writer, i[0].toString() );
}
writer.write("---------------------------------------------\n");
pxWriteLine(writer, L"---------------------------------------------");
}
}
// Adds new game data to the database, and sets curGame to the new game...
// If searchDB is true, it searches the database to see if game already exists.
void addGame(const string& id, bool searchDB = true) {
void addGame(const wxString& id, bool searchDB = true) {
if (searchDB && setGame(id)) return;
Game_Data* game = new Game_Data(id);
key_pair kp(baseKey, id);
@ -195,11 +177,11 @@ public:
}
// Searches the current game's data to see if the given key exists
bool keyExists(const string& key) {
bool keyExists(const wxChar* key) {
if (curGame) {
deque<key_pair>::iterator it = curGame->kList.begin();
for ( ; it != curGame->kList.end(); ++it) {
if (strCompare(it[0].key, key)) {
if (it[0].key == key) {
return true;
}
}
@ -209,11 +191,11 @@ public:
}
// Totally Deletes the specified key/pair value from the current game's data
void deleteKey(const string& key) {
void deleteKey(const wxChar* key) {
if (curGame) {
deque<key_pair>::iterator it = curGame->kList.begin();
for ( ; it != curGame->kList.end(); ++it) {
if (strCompare(it[0].key, key)) {
if (it[0].key == key) {
curGame->kList.erase(it);
return;
}
@ -223,55 +205,68 @@ public:
}
// Gets a string representation of the 'value' for the given key
string getString(const string& key) {
wxString getString(const wxChar* key) {
if (curGame) {
deque<key_pair>::iterator it = curGame->kList.begin();
for ( ; it != curGame->kList.end(); ++it) {
if (strCompare(it[0].key, key)) {
if (it[0].key == key) {
return it[0].value;
}
}
}
else Console.Error("DataBase_Loader: Game not set!");
return string();
return wxString();
}
// Gets a wxString representation of the 'value' for the given key
wxString getStringWX(const string& key) {
return wxString(fromUTF8(getString(key).c_str()));
bool sectionExists(const wxChar* key, const wxString& value) {
return keyExists( wxsFormat(L"[%s = %s]", key, value.c_str()) );
}
// Gets a double representation of the 'value' for the given key
double getDouble(const string& key) {
return atof(getString(key).c_str());
wxString getSection(const wxChar* key, const wxString& value) {
return getString( wxsFormat(L"[%s = %s]", key, value.c_str()) );
}
// Gets a float representation of the 'value' for the given key
float getFloat(const string& key) {
return (float)atof(getString(key).c_str());
}
// Gets an integer representation of the 'value' for the given key
int getInt(const string& key) {
return strtoul(getString(key).c_str(), NULL, 0);
int getInt(const wxChar* key) {
return wxStrtoul(getString(key), NULL, 0);
}
// Gets a u8 representation of the 'value' for the given key
u8 getU8(const string& key) {
return (u8)atoi(getString(key).c_str());
u8 getU8(const wxChar* key) {
return (u8)wxAtoi(getString(key));
}
// Gets a bool representation of the 'value' for the given key
bool getBool(const string& key) {
return !!atoi(getString(key).c_str());
bool getBool(const wxChar* key) {
return !!wxAtoi(getString(key));
}
wxString getString(const char* key) {
return getString(fromUTF8(key));
}
bool keyExists(const char* key) {
return keyExists(fromUTF8(key));
}
int getInt(const char* key) {
return getInt(fromUTF8(key));
}
u8 getU8(const char* key) {
return getU8(fromUTF8(key));
}
bool getBool(const char* key) {
return getBool(fromUTF8(key));
}
// Write a string value to the specified key
void writeString(const string& key, const string& value) {
void writeString(const wxString& key, const wxString& value) {
if (curGame) {
deque<key_pair>::iterator it = curGame->kList.begin();
for ( ; it != curGame->kList.end(); ++it) {
if (strCompare(it[0].key, key)) {
if (it[0].key == key) {
it[0].value = value;
return;
}
@ -282,52 +277,21 @@ public:
else Console.Error("DataBase_Loader: Game not set!");
}
// Write a wxString value to the specified key
void writeStringWX(const string& key, const wxString& value) {
writeString(key, value.ToUTF8().data());
}
// Write a double value to the specified key
void writeDouble(const string& key, double value) {
writeString(key, toString(value));
}
// Write a float value to the specified key
void writeFloat(const string& key, float value) {
writeString(key, toString(value));
}
// Write an integer value to the specified key
void writeInt(const string& key, int value) {
writeString(key, toString(value));
}
// Write a u8 value to the specified key
void writeU8(const string& key, u8 value) {
writeString(key, toString(value));
}
// Write a bool value to the specified key
void writeBool(const string& key, bool value) {
writeString(key, toString(value?1:0));
void writeBool(const wxString& key, bool value) {
writeString(key, value ? L"1" : L"0");
}
};
template string DataBase_Loader::toString<double>(const double& value);
template string DataBase_Loader::toString<float> (const float& value);
template string DataBase_Loader::toString<int> (const int& value);
template string DataBase_Loader::toString<u8> (const u8& value);
template string DataBase_Loader::toString<bool> (const bool& value);
static wxString compatToStringWX(int compat) {
switch (compat) {
case 6: return wxString(L"Perfect");
case 5: return wxString(L"Playable");
case 4: return wxString(L"In-Game");
case 3: return wxString(L"Menu");
case 2: return wxString(L"Intro");
case 1: return wxString(L"Nothing");
default: return wxString(L"Unknown");
case 6: return L"Perfect";
case 5: return L"Playable";
case 4: return L"In-Game";
case 3: return L"Menu";
case 2: return L"Intro";
case 1: return L"Nothing";
default: return L"Unknown";
}
}

View File

@ -16,126 +16,3 @@
#pragma once
using namespace std;
class File_Reader {
private:
char buff[2048];
template<class T> T _read() {
if (fs->eof()) throw 1;
T t; (*fs) >> t;
if (fs->fail()) throw 1;
return t;
}
public:
fstream* fs;
File_Reader(const string& filename) {
fs = new fstream(filename.c_str(), ios_base::in);
}
virtual ~File_Reader() throw() {
if (fs) fs->close();
delete fs;
}
template<class T> void read(T &t) {
long pos = fs->tellp();
string s( _read<string>() );
if (s.length() >= 2) {
if (s[0] == '/' && s[1] == '/') {
fs->seekp(pos);
fs->getline(buff, sizeof(buff));
read(t);
return;
}
}
fs->seekp(pos);
t = _read<T>();
}
void readRaw(void* ptr, int size) {
u8* p = (u8*)ptr;
for (int i = 0; i < size; i++) {
p[i] = _read<u8>();
}
}
void ignoreLine() {
fs->getline(buff, sizeof(buff));
}
string getLine() {
if (fs->eof()) throw 1;
fs->getline(buff, sizeof(buff));
if (fs->fail()) throw 1;
string ret(buff);
int eol = ret.rfind("\r");
if (eol != string::npos) ret = ret.substr(0, eol);
return ret;
}
template<class T> void readLine(T& str) {
if (fs->eof()) throw 1;
fs->getline(buff, sizeof(buff));
if (fs->fail()) throw 1;
string t(buff);
str = t;
}
};
class File_Writer {
public:
ScopedPtr<fstream> fs;
File_Writer(const string& filename) {
fs = new fstream(filename.c_str(), ios_base::out);
}
virtual ~File_Writer() throw() { }
template<class T> void write(const T& t) {
(*fs) << t;
}
void writeRaw(const void* ptr, int size) {
const u8* p = (u8*)ptr;
for (int i = 0; i < size; i++) {
write(p[i]);
}
}
};
class String_Stream {
private:
char buff[2048];
public:
stringstream* ss;
String_Stream() {
ss = new stringstream(stringstream::in | stringstream::out);
}
String_Stream(const string& str) {
ss = new stringstream(str, stringstream::in | stringstream::out);
}
virtual ~String_Stream() throw() {
delete ss;
}
template<class T> void write(const T& t) {
(*ss) << t;
}
template<class T> void read(T& t) {
(*ss) >> t;
}
string toString() {
return ss->str();
}
string getLine() {
ss->getline(buff, sizeof(buff));
return buff;
}
wxString getLineWX() {
ss->getline(buff, sizeof(buff));
return wxString(fromUTF8(buff));
}
bool finished() {
return ss->eof() || ss->fail();
}
};
static bool fileExists(const string& file) {
FILE *f = fopen(file.c_str(), "r");
if (!f) return false;
fclose(f);
return true;
}

View File

@ -76,13 +76,13 @@ void inifile_trim( wxString& buffer )
if( buffer.Length() <= 1 ) // this I'm not sure about... - air
{
buffer.Clear();
buffer.Empty();
return;
}
if( buffer.Left( 2 ) == L"//" )
{
buffer.Clear();
buffer.Empty();
return;
}
@ -120,14 +120,12 @@ void inifile_command(bool isCheat, const wxString& cmd)
// This routine receives a string containing patches, trims it,
// Then sends the command to be parsed.
void TrimPatches(string& s)
void TrimPatches(wxString& s)
{
String_Stream ss(s);
wxString buff;
while (!ss.finished()) {
buff = ss.getLineWX();
inifile_trim(buff);
if (!buff.IsEmpty()) inifile_command(0, buff);
wxStringTokenizer tkn( s, L"\n" );
while(tkn.HasMoreTokens()) {
inifile_command(0, tkn.GetNextToken());
}
}
@ -136,17 +134,17 @@ void TrimPatches(string& s)
int InitPatches(const wxString& name)
{
bool patchFound = false;
string patch;
string crc = string(name.ToUTF8().data());
wxString patch;
const wxString crc( L"[patches = " + name + L"]" );
patchnumber = 0;
if (GameDB && GameDB->gameLoaded()) {
if (GameDB->keyExists("[patches = " + crc + "]")) {
patch = GameDB->getString("[patches = " + crc + "]");
if (GameDB->sectionExists(L"patches", name)) {
patch = GameDB->getSection(L"patches", name);
patchFound = true;
}
else if (GameDB->keyExists("[patches]")) {
patch = GameDB->getString("[patches]");
else if (GameDB->keyExists(L"[patches]")) {
patch = GameDB->getString(L"[patches]");
patchFound = true;
}
}

View File

@ -587,8 +587,8 @@ void __fastcall eeGameStarting()
if (GameDB && GameDB->gameLoaded()) {
int compat = GameDB->getInt("Compat");
gameName = GameDB->getStringWX("Name");
gameName += L" (" + GameDB->getStringWX("Region") + L")";
gameName = GameDB->getString("Name");
gameName += L" (" + GameDB->getString("Region") + L")";
gameCompat = L" [Status = "+compatToStringWX(compat)+L"]";
}

View File

@ -693,7 +693,7 @@ void AppLoadSettings()
g_Conf->LoadSave( loader );
if( !wxFile::Exists( g_Conf->CurrentIso ) )
g_Conf->CurrentIso.Clear();
g_Conf->CurrentIso.clear();
sApp.DispatchEvent( loader );
}
@ -703,7 +703,7 @@ void AppSaveSettings()
if( wxGetApp().PostMethodMyself(AppSaveSettings) ) return;
if( !wxFile::Exists( g_Conf->CurrentIso ) )
g_Conf->CurrentIso.Clear();
g_Conf->CurrentIso.clear();
sApp.GetRecentIsoManager().Add( g_Conf->CurrentIso );

View File

@ -27,6 +27,8 @@ using namespace Panels;
Dialogs::SysConfigDialog::SysConfigDialog(wxWindow* parent)
: BaseConfigurationDialog( parent, _("PS2 Settings - PCSX2"), 580 )
{
ScopedBusyCursor busy( Cursor_ReallyBusy );
CreateListbook( wxGetApp().GetImgList_Config() );
const AppImageIds::ConfigIds& cfgid( wxGetApp().GetImgId().Config );
@ -45,6 +47,8 @@ Dialogs::SysConfigDialog::SysConfigDialog(wxWindow* parent)
Dialogs::ComponentsConfigDialog::ComponentsConfigDialog(wxWindow* parent)
: BaseConfigurationDialog( parent, _("Application Settings - PCSX2"), 600 )
{
ScopedBusyCursor busy( Cursor_ReallyBusy );
CreateListbook( wxGetApp().GetImgList_Config() );
const AppImageIds::ConfigIds& cfgid( wxGetApp().GetImgId().Config );

View File

@ -25,7 +25,7 @@ using namespace pxSizerFlags;
}
#define placeTextBox(wxBox, txt) { \
sizer1 += Label(txt); \
sizer1 += Label(_(txt)); \
sizer1 += 5; \
sizer1 += wxBox | pxCenter; \
sizer1 += 5; \
@ -39,8 +39,8 @@ wxTextCtrl* CreateMultiLineTextCtrl( wxWindow* parent, int digits, long flags =
return ctrl;
}
Panels::GameDatabasePanel::GameDatabasePanel( wxWindow* parent ) :
BaseApplicableConfigPanel( parent )
Panels::GameDatabasePanel::GameDatabasePanel( wxWindow* parent )
: BaseApplicableConfigPanel( parent )
{
if (!GameDB) GameDB = new DataBase_Loader();
searchBtn = new wxButton (this, wxID_DEFAULT, L"Search");
@ -65,7 +65,7 @@ Panels::GameDatabasePanel::GameDatabasePanel( wxWindow* parent ) :
*this += Heading(_("Game Database Editor")).Bold() | StdExpand();
*this += Heading(_("This panel lets you add and edit game titles, game fixes, and game patches.")) | StdExpand();
wxFlexGridSizer& sizer1(*new wxFlexGridSizer(5));
wxFlexGridSizer& sizer1(*new wxFlexGridSizer(5, StdPadding));
sizer1.AddGrowableCol(0);
blankLine();
@ -75,11 +75,11 @@ Panels::GameDatabasePanel::GameDatabasePanel( wxWindow* parent ) :
sizer1 += 5;
sizer1 += searchBtn;
placeTextBox(nameBox, L"Name: ");
placeTextBox(regionBox, L"Region: ");
placeTextBox(compatBox, L"Compatibility: ");
placeTextBox(commentBox, L"Comments: ");
placeTextBox(patchesBox, L"Patches: ");
placeTextBox(nameBox, "Name: ");
placeTextBox(regionBox, "Region: ");
placeTextBox(compatBox, "Compatibility: ");
placeTextBox(commentBox, "Comments: ");
placeTextBox(patchesBox, "Patches: ");
blankLine();
@ -102,12 +102,12 @@ Panels::GameDatabasePanel::GameDatabasePanel( wxWindow* parent ) :
void Panels::GameDatabasePanel::PopulateFields() {
if (GameDB->gameLoaded()) {
serialBox ->SetLabel(GameDB->getStringWX("Serial"));
nameBox ->SetLabel(GameDB->getStringWX("Name"));
regionBox ->SetLabel(GameDB->getStringWX("Region"));
compatBox ->SetLabel(GameDB->getStringWX("Compat"));
commentBox->SetLabel(GameDB->getStringWX("[comments]"));
patchesBox->SetLabel(GameDB->getStringWX("[patches]"));
serialBox ->SetLabel(GameDB->getString("Serial"));
nameBox ->SetLabel(GameDB->getString("Name"));
regionBox ->SetLabel(GameDB->getString("Region"));
compatBox ->SetLabel(GameDB->getString("Compat"));
commentBox->SetLabel(GameDB->getString("[comments]"));
patchesBox->SetLabel(GameDB->getString("[patches]"));
gameFixes[0]->SetValue(GameDB->getBool("VuAddSubHack"));
gameFixes[1]->SetValue(GameDB->getBool("VuClipFlagHack"));
gameFixes[2]->SetValue(GameDB->getBool("FpuCompareHack"));
@ -131,23 +131,22 @@ void Panels::GameDatabasePanel::PopulateFields() {
}
}
#define writeTextBoxToDB(_key, _value) { \
if (_value.IsEmpty()) GameDB->deleteKey(_key); \
else GameDB->writeStringWX(_key, _value); \
#define writeTextBoxToDB(_key, _value) { \
if (_value.IsEmpty()) GameDB->deleteKey(wxT(_key)); \
else GameDB->writeString(wxT(_key), _value); \
}
#define writeGameFixToDB(_key, _value) { \
if (!_value) GameDB->deleteKey(_key); \
else GameDB->writeBool(_key, _value); \
#define writeGameFixToDB(_key, _value) { \
if (!_value) GameDB->deleteKey(wxT(_key)); \
else GameDB->writeBool(wxT(_key), _value); \
}
void Panels::GameDatabasePanel::WriteFieldsToDB() {
wxString wxStr = serialBox->GetValue();
string str = wxStr.ToUTF8().data();
wxString wxStr( serialBox->GetValue() );
if (wxStr.IsEmpty()) return;
if (str.compare(GameDB->getString("Serial"))) {
GameDB->addGame(str);
if (wxStr == GameDB->getString("Serial")) {
GameDB->addGame(wxStr);
}
writeTextBoxToDB("Name", nameBox->GetValue());
@ -168,10 +167,11 @@ void Panels::GameDatabasePanel::WriteFieldsToDB() {
void Panels::GameDatabasePanel::Search_Click(wxCommandEvent& evt) {
wxString wxStr = serialBox->GetValue();
string str = wxStr.IsEmpty() ? DiscID.ToUTF8().data() : wxStr.ToUTF8().data();
if( wxStr.IsEmpty() ) wxStr = DiscID;
bool bySerial = 1;//searchType->GetSelection()==0;
if (bySerial) GameDB->setGame(str);
if (bySerial) GameDB->setGame(wxStr);
PopulateFields();
evt.Skip();

View File

@ -20,13 +20,6 @@
using namespace pxSizerFlags;
static int pxGetTextHeight( const wxWindow* wind, int rows )
{
wxClientDC dc(wx_const_cast(wxWindow *, wind));
dc.SetFont( wind->GetFont() );
return (dc.GetCharHeight() + 1 ) * rows;
}
const wxChar* Panels::SpeedHacksPanel::GetEEcycleSliderMsg( int val )
{
switch( val )
@ -132,7 +125,7 @@ Panels::SpeedHacksPanel::SpeedHacksPanel( wxWindow* parent )
m_msg_eecycle = new pxStaticHeading( eeSliderPanel );
m_msg_eecycle->SetForegroundColour( wxColour( L"Red" ) );
m_msg_eecycle->SetMinSize( wxSize( wxDefaultCoord, pxGetTextHeight(m_msg_eecycle, 3) ) );
m_msg_eecycle->SetHeight(3);
const wxChar* ee_tooltip = pxE( ".Tooltip:Speedhacks:EECycleRate Slider",
L"Setting higher values on this slider effectively reduces the clock speed of the EmotionEngine's "
@ -153,7 +146,7 @@ Panels::SpeedHacksPanel::SpeedHacksPanel( wxWindow* parent )
m_msg_vustealer = new pxStaticHeading( vuSliderPanel );
m_msg_vustealer->SetForegroundColour( wxColour( L"Red" ) );
m_msg_vustealer->SetMinSize( wxSize( wxDefaultCoord, pxGetTextHeight(m_msg_vustealer, 3) ) );
m_msg_vustealer->SetHeight(3);
const wxChar* vu_tooltip = pxE( ".Tooltip:Speedhacks:VUCycleStealing Slider",
L"This slider controls the amount of cycles the VU unit steals from the EmotionEngine. Higher values increase the number of "