Allow to mark preferences as immutable or deprecated

- Deprecated: The option is read from the settings, but not written back
  when saving. This can be used for migrating options to a new name or
  format. (Not used yet.)
- Immutable: The option can not be changed from Lua. Used for
  security-relevant options that should not be changable by the theme or
  mod charts. Currently that's networking and some file system access
  options.
This commit is contained in:
Martin Natano
2022-02-20 17:24:43 +01:00
parent eb0ab83d89
commit d8b6d36a78
6 changed files with 55 additions and 23 deletions
+9 -5
View File
@@ -9,9 +9,10 @@
static SubscriptionManager<IPreference> m_Subscribers;
IPreference::IPreference( const RString& sName ):
IPreference::IPreference( const RString& sName, PreferenceType type ):
m_sName( sName ),
m_bIsStatic( false )
m_bDoNotWrite( type == PreferenceType::Deprecated ),
m_bImmutable( type == PreferenceType::Immutable )
{
m_Subscribers.Subscribe( this );
}
@@ -81,14 +82,17 @@ void IPreference::ReadFrom( const XNode* pNode, bool bIsStatic )
if( pNode->GetAttrValue(m_sName, sVal) )
{
FromString( sVal );
m_bIsStatic = bIsStatic;
if (bIsStatic)
m_bDoNotWrite = true;
}
}
void IPreference::WriteTo( XNode* pNode ) const
{
if( !m_bIsStatic )
pNode->AppendAttr( m_sName, ToString() );
if (m_bDoNotWrite)
return;
pNode->AppendAttr( m_sName, ToString() );
}
/* Load our value from the node, and make it the new default. */