don't write values to Preferences.ini that are in Static.ini

This commit is contained in:
Chris Danford
2006-03-20 04:57:15 +00:00
parent fd22fbf721
commit 1bb78b396c
4 changed files with 50 additions and 27 deletions
+8 -5
View File
@@ -37,12 +37,11 @@ void IPreference::LoadAllDefaults()
(*p)->LoadDefault(); (*p)->LoadDefault();
} }
void IPreference::ReadAllPrefsFromNode( const XNode* pNode ) void IPreference::ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic )
{ {
if( pNode == NULL ) ASSERT( pNode );
return;
FOREACHS_CONST( IPreference*, *m_Subscribers.m_pSubscribers, p ) FOREACHS_CONST( IPreference*, *m_Subscribers.m_pSubscribers, p )
(*p)->ReadFrom( pNode ); (*p)->ReadFrom( pNode, bIsStatic );
} }
void IPreference::SavePrefsToNode( XNode* pNode ) void IPreference::SavePrefsToNode( XNode* pNode )
@@ -97,15 +96,19 @@ READFROM_AND_WRITETO( float )
READFROM_AND_WRITETO( bool ) READFROM_AND_WRITETO( bool )
READFROM_AND_WRITETO( RString ) READFROM_AND_WRITETO( RString )
void IPreference::ReadFrom( const XNode* pNode ) void IPreference::ReadFrom( const XNode* pNode, bool bIsStatic )
{ {
RString sVal; RString sVal;
if( pNode->GetAttrValue(m_sName, sVal) ) if( pNode->GetAttrValue(m_sName, sVal) )
{
FromString( sVal ); FromString( sVal );
m_bLoadedFromStatic = bIsStatic;
}
} }
void IPreference::WriteTo( XNode* pNode ) const void IPreference::WriteTo( XNode* pNode ) const
{ {
if( !m_bLoadedFromStatic )
pNode->AppendAttr( m_sName, ToString() ); pNode->AppendAttr( m_sName, ToString() );
} }
+22 -7
View File
@@ -13,7 +13,7 @@ class IPreference
public: public:
IPreference( const RString& sName ); IPreference( const RString& sName );
virtual ~IPreference(); virtual ~IPreference();
void ReadFrom( const XNode* pNode ); void ReadFrom( const XNode* pNode, bool bIsStatic );
void WriteTo( XNode* pNode ) const; void WriteTo( XNode* pNode ) const;
void ReadDefaultFrom( const XNode* pNode ); void ReadDefaultFrom( const XNode* pNode );
@@ -30,12 +30,14 @@ public:
static IPreference *GetPreferenceByName( const RString &sName ); static IPreference *GetPreferenceByName( const RString &sName );
static void LoadAllDefaults(); static void LoadAllDefaults();
static void ReadAllPrefsFromNode( const XNode* pNode ); static void ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic );
static void SavePrefsToNode( XNode* pNode ); static void SavePrefsToNode( XNode* pNode );
static void ReadAllDefaultsFromNode( const XNode* pNode ); static void ReadAllDefaultsFromNode( const XNode* pNode );
protected: RString GetName() { return m_sName; }
private:
RString m_sName; RString m_sName;
bool m_bLoadedFromStatic; // loaded from Static.ini? If so, don't write to Preferences.ini
}; };
void BroadcastPreferenceChanged( const RString& sPreferenceName ); void BroadcastPreferenceChanged( const RString& sPreferenceName );
@@ -59,9 +61,22 @@ public:
} }
RString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); } RString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); }
void FromString( const RString &s ) { PrefFromString( s, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); } void FromString( const RString &s )
void SetFromStack( lua_State *L ) { PrefSetFromStack( L, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); } {
void PushValue( lua_State *L ) const { PrefPushValue( L, (BasicType &)m_currentValue ); } PrefFromString( s, (BasicType &)m_currentValue );
if( m_pfnValidate )
m_pfnValidate( m_currentValue );
}
void SetFromStack( lua_State *L )
{
PrefSetFromStack( L, (BasicType &)m_currentValue );
if( m_pfnValidate )
m_pfnValidate( m_currentValue );
}
void PushValue( lua_State *L ) const
{
PrefPushValue( L, (BasicType &)m_currentValue );
}
void LoadDefault() void LoadDefault()
{ {
@@ -85,7 +100,7 @@ public:
void Set( const T& other ) void Set( const T& other )
{ {
m_currentValue = other; m_currentValue = other;
BroadcastPreferenceChanged( m_sName ); BroadcastPreferenceChanged( GetName() );
} }
private: private:
+15 -10
View File
@@ -385,7 +385,7 @@ void PrefsManager::RestoreGamePrefs()
m_sDefaultModifiers .Set( gp.m_sDefaultModifiers ); m_sDefaultModifiers .Set( gp.m_sDefaultModifiers );
// give Static.ini a chance to clobber the saved game prefs // give Static.ini a chance to clobber the saved game prefs
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true );
} }
void PrefsManager::ReadPrefsFromDisk() void PrefsManager::ReadPrefsFromDisk()
@@ -393,9 +393,9 @@ void PrefsManager::ReadPrefsFromDisk()
ReadDefaultsFromFile( SpecialFiles::DEFAULTS_INI_PATH, GetPreferencesSection() ); ReadDefaultsFromFile( SpecialFiles::DEFAULTS_INI_PATH, GetPreferencesSection() );
IPreference::LoadAllDefaults(); IPreference::LoadAllDefaults();
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" ); ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options", false );
ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH ); ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true );
if( !m_sCurrentGame.Get().empty() ) if( !m_sCurrentGame.Get().empty() )
RestoreGamePrefs(); RestoreGamePrefs();
@@ -406,31 +406,34 @@ void PrefsManager::ResetToFactoryDefaults()
// clobber the users prefs by initing then applying defaults // clobber the users prefs by initing then applying defaults
Init(); Init();
IPreference::LoadAllDefaults(); IPreference::LoadAllDefaults();
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true );
SavePrefsToDisk(); SavePrefsToDisk();
} }
void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection ) void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection, bool bIsStatic )
{ {
IniFile ini; IniFile ini;
if( !ini.ReadFile(sIni) ) if( !ini.ReadFile(sIni) )
return; return;
ReadPrefsFromIni( ini, sSection ); ReadPrefsFromIni( ini, sSection, bIsStatic );
} }
static const RString GAME_SECTION_PREFIX = "Game-"; static const RString GAME_SECTION_PREFIX = "Game-";
void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection ) void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection, bool bIsStatic )
{ {
// Apply our fallback recursively (if any) before applying ourself. // Apply our fallback recursively (if any) before applying ourself.
// TODO: detect circular? static int s_iDepth = 0;
s_iDepth++;
ASSERT( s_iDepth < 100 );
RString sFallback; RString sFallback;
if( ini.GetValue(sSection,"Fallback",sFallback) ) if( ini.GetValue(sSection,"Fallback",sFallback) )
{ {
ReadPrefsFromIni( ini, sFallback ); ReadPrefsFromIni( ini, sFallback, bIsStatic );
} }
s_iDepth--;
//IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName ); //IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName );
// if( pPref == NULL ) // if( pPref == NULL )
@@ -440,7 +443,9 @@ void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection
// } // }
// pPref->FromString( sVal ); // pPref->FromString( sVal );
IPreference::ReadAllPrefsFromNode( ini.GetChild(sSection) ); const XNode *pChild = ini.GetChild(sSection);
if( pChild )
IPreference::ReadAllPrefsFromNode( pChild, bIsStatic );
} }
void PrefsManager::ReadGamePrefsFromIni( const RString &sIni ) void PrefsManager::ReadGamePrefsFromIni( const RString &sIni )
+2 -2
View File
@@ -241,7 +241,7 @@ public:
float GetSoundVolume(); float GetSoundVolume();
void ReadPrefsFromIni( const IniFile &ini, const RString &sSection ); void ReadPrefsFromIni( const IniFile &ini, const RString &sSection, bool bIsStatic );
void ReadGamePrefsFromIni( const RString &sIni ); void ReadGamePrefsFromIni( const RString &sIni );
void ReadDefaultsFromIni( const IniFile &ini, const RString &sSection ); void ReadDefaultsFromIni( const IniFile &ini, const RString &sSection );
void SavePrefsToIni( IniFile &ini ); void SavePrefsToIni( IniFile &ini );
@@ -257,7 +257,7 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
protected: protected:
void ReadPrefsFromFile( const RString &sIni, const RString &sSection ); void ReadPrefsFromFile( const RString &sIni, const RString &sSection, bool bIsStatic );
void ReadDefaultsFromFile( const RString &sIni, const RString &sSection ); void ReadDefaultsFromFile( const RString &sIni, const RString &sSection );
}; };