2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* 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.
|
2009-04-27 02:04:31 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-04-27 02:04:31 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "IniInterface.h"
|
|
|
|
|
2009-09-05 23:07:23 +00:00
|
|
|
static int _calcEnumLength( const wxChar* const* enumArray )
|
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
while( *enumArray != NULL )
|
|
|
|
{
|
|
|
|
enumArray++;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniScopedGroup::IniScopedGroup( IniInterface& mommy, const wxString& group )
|
|
|
|
: m_mom( mommy )
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
pxAssertDev( wxStringTokenize( group, L"/" ).Count() <= 1, L"Cannot nest more than one group deep per instance of IniScopedGroup." );
|
|
|
|
m_mom.SetPath( group );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniScopedGroup::~IniScopedGroup()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
m_mom.SetPath( L".." );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniInterface (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
IniInterface::IniInterface( wxConfigBase& config )
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config = &config;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniInterface::IniInterface( wxConfigBase* config )
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config = config;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniInterface::IniInterface()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config = wxConfigBase::Get( false );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
IniInterface::~IniInterface()
|
2009-08-21 04:44:47 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
Flush();
|
2009-08-21 04:44:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
void IniInterface::SetPath( const wxString& path )
|
2009-08-21 04:44:47 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->SetPath( path );
|
2009-08-21 04:44:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
void IniInterface::Flush()
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->Flush();
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniLoader (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
IniLoader::IniLoader( wxConfigBase& config ) : IniInterface( config ) { }
|
|
|
|
IniLoader::IniLoader( wxConfigBase* config ) : IniInterface( config ) { }
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
IniLoader::IniLoader() : IniInterface() {}
|
2010-01-08 07:11:33 +00:00
|
|
|
IniLoader::~IniLoader() throw() {}
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, wxString& value, const wxString& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config )
|
|
|
|
m_Config->Read( var, &value, defvalue );
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-04 20:53:05 +00:00
|
|
|
void IniLoader::Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue )
|
|
|
|
{
|
|
|
|
wxString dest;
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->Read( var, &dest, wxEmptyString );
|
2009-07-04 20:53:05 +00:00
|
|
|
|
|
|
|
if( dest.IsEmpty() )
|
|
|
|
value = defvalue;
|
|
|
|
else
|
|
|
|
value = dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
wxString dest( defvalue.GetFullPath() );
|
|
|
|
if( m_Config ) m_Config->Read( var, &dest, defvalue.GetFullPath() );
|
2009-07-04 20:53:05 +00:00
|
|
|
value = dest;
|
|
|
|
}
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
void IniLoader::Entry( const wxString& var, int& value, const int defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config )
|
|
|
|
m_Config->Read( var, &value, defvalue );
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, uint& value, const uint defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config )
|
|
|
|
m_Config->Read( var, (int*)&value, (int)defvalue );
|
|
|
|
else
|
|
|
|
value = defvalue;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, bool& value, const bool defvalue )
|
|
|
|
{
|
2009-07-20 00:39:38 +00:00
|
|
|
// TODO : Stricter value checking on enabled/disabled?
|
2010-06-06 23:26:07 +00:00
|
|
|
wxString dest(defvalue ? L"enabled" : L"disabled");
|
|
|
|
if( m_Config ) m_Config->Read( var, &dest, dest );
|
2009-08-20 14:34:48 +00:00
|
|
|
value = (dest == L"enabled") || (dest == L"1");
|
2009-07-20 00:39:38 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
bool IniLoader::EntryBitBool( const wxString& var, bool value, const bool defvalue )
|
2009-07-20 00:39:38 +00:00
|
|
|
{
|
|
|
|
// Note: 'value' param is used by inisaver only.
|
|
|
|
bool result;
|
|
|
|
Entry( var, result, defvalue );
|
|
|
|
return result;
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
int IniLoader::EntryBitfield( const wxString& var, int value, const int defvalue )
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
Entry( var, result, defvalue );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
void IniLoader::Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue )
|
|
|
|
{
|
|
|
|
// Note: the "easy" way would be to convert to double and load/save that, but floating point
|
|
|
|
// has way too much rounding error so we really need to do things out manually.. >_<
|
|
|
|
|
|
|
|
wxString readval( value.ToString() );
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->Read( var, &readval );
|
2009-12-03 15:51:39 +00:00
|
|
|
value = Fixed100::FromString( readval, value );
|
|
|
|
}
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
void IniLoader::Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config )
|
|
|
|
{
|
|
|
|
value = defvalue; return;
|
|
|
|
}
|
|
|
|
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, wxSize& value, const wxSize& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config )
|
|
|
|
{
|
|
|
|
value = defvalue; return;
|
|
|
|
}
|
|
|
|
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config )
|
|
|
|
{
|
|
|
|
value = defvalue; return;
|
|
|
|
}
|
|
|
|
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 09:30:22 +00:00
|
|
|
void IniLoader::_EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2009-09-05 23:07:23 +00:00
|
|
|
// Confirm default value sanity...
|
|
|
|
|
|
|
|
const int cnt = _calcEnumLength( enumArray );
|
2009-11-04 09:30:22 +00:00
|
|
|
if( !IndexBoundsCheck( L"IniLoader EnumDefaultValue", defvalue, cnt ) )
|
|
|
|
{
|
|
|
|
Console.Error( "(LoadSettings) Default enumeration index is out of bounds. Truncating." );
|
|
|
|
defvalue = cnt-1;
|
|
|
|
}
|
2009-09-05 23:07:23 +00:00
|
|
|
|
|
|
|
// Sanity confirmed, proceed with craziness!
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config )
|
|
|
|
{
|
|
|
|
value = defvalue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
wxString retval;
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Read( var, &retval, enumArray[defvalue] );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
int i=0;
|
|
|
|
while( enumArray[i] != NULL && ( retval != enumArray[i] ) ) i++;
|
|
|
|
|
|
|
|
if( enumArray[i] == NULL )
|
|
|
|
{
|
2009-11-04 09:30:22 +00:00
|
|
|
Console.Warning( L"(LoadSettings) Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.",
|
2009-09-08 05:37:40 +00:00
|
|
|
retval.c_str(), var.c_str(), enumArray[defvalue]
|
2009-10-29 13:32:40 +00:00
|
|
|
);
|
2009-04-27 02:04:31 +00:00
|
|
|
value = defvalue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = i;
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// IniSaver (implementations)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IniSaver::IniSaver( wxConfigBase& config ) : IniInterface( config ) { }
|
|
|
|
IniSaver::IniSaver( wxConfigBase* config ) : IniInterface( config ) { }
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
IniSaver::IniSaver() : IniInterface() {}
|
|
|
|
IniSaver::~IniSaver() {}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, wxString& value, const wxString& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, value );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-04 20:53:05 +00:00
|
|
|
void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
|
2009-10-26 08:57:30 +00:00
|
|
|
/*if( value == defvalue )
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Write( var, wxString() );
|
2009-10-26 08:57:30 +00:00
|
|
|
else*/
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Write( var, value.ToString() );
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, value.GetFullPath() );
|
2009-07-04 20:53:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
void IniSaver::Entry( const wxString& var, int& value, const int defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, value );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, uint& value, const uint defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, (int)value );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, bool& value, const bool defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, value ? L"enabled" : L"disabled" );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
bool IniSaver::EntryBitBool( const wxString& var, bool value, const bool defvalue )
|
2009-07-20 00:39:38 +00:00
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->Write( var, value ? L"enabled" : L"disabled" );
|
2009-07-20 00:39:38 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-07-23 02:11:45 +00:00
|
|
|
int IniSaver::EntryBitfield( const wxString& var, int value, const int defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( m_Config ) m_Config->Write( var, value );
|
2009-07-23 02:11:45 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
void IniSaver::Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
// Note: the "easy" way would be to convert to double and load/save that, but floating point
|
|
|
|
// has way too much rounding error so we really need to do things out manually, using strings.
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Write( var, value.ToString() );
|
2009-12-03 15:51:39 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
void IniSaver::Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, ToString( value ) );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, wxSize& value, const wxSize& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, ToString( value ) );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IniSaver::Entry( const wxString& var, wxRect& value, const wxRect& defvalue )
|
|
|
|
{
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
m_Config->Write( var, ToString( value ) );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 09:30:22 +00:00
|
|
|
void IniSaver::_EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue )
|
2009-04-27 02:04:31 +00:00
|
|
|
{
|
2009-09-05 23:07:23 +00:00
|
|
|
const int cnt = _calcEnumLength( enumArray );
|
2009-11-04 09:30:22 +00:00
|
|
|
|
|
|
|
// Confirm default value sanity...
|
|
|
|
|
|
|
|
if( !IndexBoundsCheck( L"IniSaver EnumDefaultValue", defvalue, cnt ) )
|
|
|
|
{
|
|
|
|
Console.Error( "(SaveSettings) Default enumeration index is out of bounds. Truncating." );
|
|
|
|
defvalue = cnt-1;
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
if( !m_Config ) return;
|
|
|
|
|
2009-09-05 23:07:23 +00:00
|
|
|
if( value >= cnt )
|
|
|
|
{
|
2009-11-15 06:26:55 +00:00
|
|
|
Console.Warning( L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", var.c_str() );
|
2010-04-25 00:31:27 +00:00
|
|
|
Console.Indent().Warning(
|
2009-11-15 06:26:55 +00:00
|
|
|
L"Illegal Value: %d\n"
|
|
|
|
L"Using Default: %d (%s)\n",
|
|
|
|
value, defvalue, enumArray[defvalue]
|
2009-09-05 23:07:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Cause a debug assertion, since this is a fully recoverable error.
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
pxAssert( value < cnt );
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-05 23:07:23 +00:00
|
|
|
value = defvalue;
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:26:07 +00:00
|
|
|
m_Config->Write( var, enumArray[value] );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
2009-07-07 20:53:32 +00:00
|
|
|
|