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:
@@ -51,6 +51,14 @@ void IPreference::SavePrefsToNode( XNode* pNode )
|
|||||||
(*p)->WriteTo( 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
|
void IPreference::PushValue( lua_State *L ) const
|
||||||
{
|
{
|
||||||
if( LOG )
|
if( LOG )
|
||||||
@@ -101,6 +109,15 @@ void IPreference::WriteTo( XNode* pNode ) const
|
|||||||
pNode->AppendAttr( m_sName, ToString() );
|
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 )
|
void BroadcastPreferenceChanged( const CString& sPreferenceName )
|
||||||
{
|
{
|
||||||
if( MESSAGEMAN )
|
if( MESSAGEMAN )
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ public:
|
|||||||
virtual ~IPreference();
|
virtual ~IPreference();
|
||||||
void ReadFrom( const XNode* pNode );
|
void ReadFrom( const XNode* pNode );
|
||||||
void WriteTo( XNode* pNode ) const;
|
void WriteTo( XNode* pNode ) const;
|
||||||
|
void ReadDefaultFrom( const XNode* pNode );
|
||||||
|
|
||||||
virtual void LoadDefault() = 0;
|
virtual void LoadDefault() = 0;
|
||||||
|
virtual void SetDefaultFromString( const CString &s ) = 0;
|
||||||
|
|
||||||
virtual CString ToString() const = 0;
|
virtual CString ToString() const = 0;
|
||||||
virtual void FromString( const CString &s ) = 0;
|
virtual void FromString( const CString &s ) = 0;
|
||||||
@@ -30,6 +32,7 @@ public:
|
|||||||
static void LoadAllDefaults();
|
static void LoadAllDefaults();
|
||||||
static void ReadAllPrefsFromNode( const XNode* pNode );
|
static void ReadAllPrefsFromNode( const XNode* pNode );
|
||||||
static void SavePrefsToNode( XNode* pNode );
|
static void SavePrefsToNode( XNode* pNode );
|
||||||
|
static void ReadAllDefaultsFromNode( const XNode* pNode );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CString m_sName;
|
CString m_sName;
|
||||||
@@ -63,6 +66,10 @@ public:
|
|||||||
{
|
{
|
||||||
m_currentValue = m_defaultValue;
|
m_currentValue = m_defaultValue;
|
||||||
}
|
}
|
||||||
|
void SetDefaultFromString( const CString &s )
|
||||||
|
{
|
||||||
|
PrefFromString( s, (BasicType &)m_defaultValue );
|
||||||
|
}
|
||||||
|
|
||||||
const T &Get() const
|
const T &Get() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -379,7 +379,9 @@ void PrefsManager::RestoreGamePrefs()
|
|||||||
|
|
||||||
void PrefsManager::ReadPrefsFromDisk()
|
void PrefsManager::ReadPrefsFromDisk()
|
||||||
{
|
{
|
||||||
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
|
ReadDefaultsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
|
||||||
|
IPreference::LoadAllDefaults();
|
||||||
|
|
||||||
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" );
|
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" );
|
||||||
ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
|
ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
|
||||||
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
||||||
@@ -392,7 +394,7 @@ void PrefsManager::ResetToFactoryDefaults()
|
|||||||
{
|
{
|
||||||
// clobber the users prefs by initing then applying defaults
|
// clobber the users prefs by initing then applying defaults
|
||||||
Init();
|
Init();
|
||||||
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
|
IPreference::LoadAllDefaults();
|
||||||
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
||||||
|
|
||||||
SavePrefsToDisk();
|
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()
|
void PrefsManager::SavePrefsToDisk()
|
||||||
{
|
{
|
||||||
IniFile ini;
|
IniFile ini;
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ public:
|
|||||||
|
|
||||||
void ReadPrefsFromIni( const IniFile &ini, const CString &sSection );
|
void ReadPrefsFromIni( const IniFile &ini, const CString &sSection );
|
||||||
void ReadGamePrefsFromIni( const CString &sIni );
|
void ReadGamePrefsFromIni( const CString &sIni );
|
||||||
|
void ReadDefaultsFromIni( const IniFile &ini, const CString &sSection );
|
||||||
void SavePrefsToIni( IniFile &ini );
|
void SavePrefsToIni( IniFile &ini );
|
||||||
|
|
||||||
void ReadPrefsFromDisk();
|
void ReadPrefsFromDisk();
|
||||||
@@ -263,7 +264,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadPrefsFromFile( const CString &sIni, const CString &sSection );
|
void ReadPrefsFromFile( const CString &sIni, const CString &sSection );
|
||||||
|
void ReadDefaultsFromFile( const CString &sIni, const CString &sSection );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user