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:
+9
-5
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user