Instead of loading Defaults.ini underneith Preferences.ini, change the

actual IPreference defaults according to Defaults.ini.  This way, we can
access default values immediately, without having to load and parse a
file.  Since this simply changes the value in the preference, this doesn't
use any more memory.
This commit is contained in:
Glenn Maynard
2006-01-14 03:56:59 +00:00
parent 115e901d82
commit cdf951e589
4 changed files with 50 additions and 3 deletions
+17
View File
@@ -51,6 +51,14 @@ void IPreference::SavePrefsToNode( XNode* pNode )
(*p)->WriteTo( pNode );
}
void IPreference::ReadAllDefaultsFromNode( const XNode* pNode )
{
if( pNode == NULL )
return;
FOREACHS_CONST( IPreference*, *m_Subscribers.m_pSubscribers, p )
(*p)->ReadDefaultFrom( pNode );
}
void IPreference::PushValue( lua_State *L ) const
{
if( LOG )
@@ -101,6 +109,15 @@ void IPreference::WriteTo( XNode* pNode ) const
pNode->AppendAttr( m_sName, ToString() );
}
/* Load our value from the node, and make it the new default. */
void IPreference::ReadDefaultFrom( const XNode* pNode )
{
CString sVal;
if( !pNode->GetAttrValue(m_sName, sVal) )
return;
SetDefaultFromString( sVal );
}
void BroadcastPreferenceChanged( const CString& sPreferenceName )
{
if( MESSAGEMAN )
+7
View File
@@ -15,8 +15,10 @@ public:
virtual ~IPreference();
void ReadFrom( const XNode* pNode );
void WriteTo( XNode* pNode ) const;
void ReadDefaultFrom( const XNode* pNode );
virtual void LoadDefault() = 0;
virtual void SetDefaultFromString( const CString &s ) = 0;
virtual CString ToString() const = 0;
virtual void FromString( const CString &s ) = 0;
@@ -30,6 +32,7 @@ public:
static void LoadAllDefaults();
static void ReadAllPrefsFromNode( const XNode* pNode );
static void SavePrefsToNode( XNode* pNode );
static void ReadAllDefaultsFromNode( const XNode* pNode );
protected:
CString m_sName;
@@ -63,6 +66,10 @@ public:
{
m_currentValue = m_defaultValue;
}
void SetDefaultFromString( const CString &s )
{
PrefFromString( s, (BasicType &)m_defaultValue );
}
const T &Get() const
{
+24 -2
View File
@@ -379,7 +379,9 @@ void PrefsManager::RestoreGamePrefs()
void PrefsManager::ReadPrefsFromDisk()
{
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
ReadDefaultsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
IPreference::LoadAllDefaults();
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" );
ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
@@ -392,7 +394,7 @@ void PrefsManager::ResetToFactoryDefaults()
{
// clobber the users prefs by initing then applying defaults
Init();
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
IPreference::LoadAllDefaults();
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
SavePrefsToDisk();
@@ -454,6 +456,26 @@ void PrefsManager::ReadGamePrefsFromIni( const CString &sIni )
}
}
void PrefsManager::ReadDefaultsFromFile( const CString &sIni, const CString &sSection )
{
IniFile ini;
if( !ini.ReadFile(sIni) )
return;
ReadDefaultsFromIni( ini, sSection );
}
void PrefsManager::ReadDefaultsFromIni( const IniFile &ini, const CString &sSection )
{
// Apply our fallback recursively (if any) before applying ourself.
// TODO: detect circular?
CString sFallback;
if( ini.GetValue(sSection,"Fallback",sFallback) )
ReadDefaultsFromIni( ini, sFallback );
IPreference::ReadAllDefaultsFromNode( ini.GetChild(sSection) );
}
void PrefsManager::SavePrefsToDisk()
{
IniFile ini;
+2 -1
View File
@@ -249,6 +249,7 @@ public:
void ReadPrefsFromIni( const IniFile &ini, const CString &sSection );
void ReadGamePrefsFromIni( const CString &sIni );
void ReadDefaultsFromIni( const IniFile &ini, const CString &sSection );
void SavePrefsToIni( IniFile &ini );
void ReadPrefsFromDisk();
@@ -263,7 +264,7 @@ public:
protected:
void ReadPrefsFromFile( const CString &sIni, const CString &sSection );
void ReadDefaultsFromFile( const CString &sIni, const CString &sSection );
};