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
+9 -6
View File
@@ -37,12 +37,11 @@ void IPreference::LoadAllDefaults()
(*p)->LoadDefault();
}
void IPreference::ReadAllPrefsFromNode( const XNode* pNode )
void IPreference::ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic )
{
if( pNode == NULL )
return;
ASSERT( pNode );
FOREACHS_CONST( IPreference*, *m_Subscribers.m_pSubscribers, p )
(*p)->ReadFrom( pNode );
(*p)->ReadFrom( pNode, bIsStatic );
}
void IPreference::SavePrefsToNode( XNode* pNode )
@@ -97,16 +96,20 @@ READFROM_AND_WRITETO( float )
READFROM_AND_WRITETO( bool )
READFROM_AND_WRITETO( RString )
void IPreference::ReadFrom( const XNode* pNode )
void IPreference::ReadFrom( const XNode* pNode, bool bIsStatic )
{
RString sVal;
if( pNode->GetAttrValue(m_sName, sVal) )
{
FromString( sVal );
m_bLoadedFromStatic = bIsStatic;
}
}
void IPreference::WriteTo( XNode* pNode ) const
{
pNode->AppendAttr( m_sName, ToString() );
if( !m_bLoadedFromStatic )
pNode->AppendAttr( m_sName, ToString() );
}
/* Load our value from the node, and make it the new default. */
+23 -8
View File
@@ -13,7 +13,7 @@ class IPreference
public:
IPreference( const RString& sName );
virtual ~IPreference();
void ReadFrom( const XNode* pNode );
void ReadFrom( const XNode* pNode, bool bIsStatic );
void WriteTo( XNode* pNode ) const;
void ReadDefaultFrom( const XNode* pNode );
@@ -30,12 +30,14 @@ public:
static IPreference *GetPreferenceByName( const RString &sName );
static void LoadAllDefaults();
static void ReadAllPrefsFromNode( const XNode* pNode );
static void ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic );
static void SavePrefsToNode( XNode* pNode );
static void ReadAllDefaultsFromNode( const XNode* pNode );
protected:
RString m_sName;
RString GetName() { return m_sName; }
private:
RString m_sName;
bool m_bLoadedFromStatic; // loaded from Static.ini? If so, don't write to Preferences.ini
};
void BroadcastPreferenceChanged( const RString& sPreferenceName );
@@ -59,9 +61,22 @@ public:
}
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 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 FromString( const RString &s )
{
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()
{
@@ -85,7 +100,7 @@ public:
void Set( const T& other )
{
m_currentValue = other;
BroadcastPreferenceChanged( m_sName );
BroadcastPreferenceChanged( GetName() );
}
private:
+16 -11
View File
@@ -385,7 +385,7 @@ void PrefsManager::RestoreGamePrefs()
m_sDefaultModifiers .Set( gp.m_sDefaultModifiers );
// 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()
@@ -393,9 +393,9 @@ void PrefsManager::ReadPrefsFromDisk()
ReadDefaultsFromFile( SpecialFiles::DEFAULTS_INI_PATH, GetPreferencesSection() );
IPreference::LoadAllDefaults();
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" );
ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options", false );
ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() );
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true );
if( !m_sCurrentGame.Get().empty() )
RestoreGamePrefs();
@@ -406,31 +406,34 @@ void PrefsManager::ResetToFactoryDefaults()
// clobber the users prefs by initing then applying defaults
Init();
IPreference::LoadAllDefaults();
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() );
ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true );
SavePrefsToDisk();
}
void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection )
void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection, bool bIsStatic )
{
IniFile ini;
if( !ini.ReadFile(sIni) )
return;
ReadPrefsFromIni( ini, sSection );
ReadPrefsFromIni( ini, sSection, bIsStatic );
}
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.
// TODO: detect circular?
static int s_iDepth = 0;
s_iDepth++;
ASSERT( s_iDepth < 100 );
RString sFallback;
if( ini.GetValue(sSection,"Fallback",sFallback) )
{
ReadPrefsFromIni( ini, sFallback );
ReadPrefsFromIni( ini, sFallback, bIsStatic );
}
s_iDepth--;
//IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName );
// if( pPref == NULL )
@@ -440,7 +443,9 @@ void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection
// }
// 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 )
@@ -505,7 +510,7 @@ void PrefsManager::SavePrefsToIni( IniFile &ini )
RString sSection = "Game-" + RString( iter->first );
ini.SetValue( sSection, "Announcer", iter->second.m_sAnnouncer );
ini.SetValue( sSection, "Theme", iter->second.m_sTheme );
ini.SetValue( sSection, "Theme", iter->second.m_sTheme );
ini.SetValue( sSection, "DefaultModifiers", iter->second.m_sDefaultModifiers );
}
}
+2 -2
View File
@@ -241,7 +241,7 @@ public:
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 ReadDefaultsFromIni( const IniFile &ini, const RString &sSection );
void SavePrefsToIni( IniFile &ini );
@@ -257,7 +257,7 @@ public:
void PushSelf( lua_State *L );
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 );
};