(ISettingsManager): new public interface.

This commit is contained in:
morkt 2018-01-11 18:38:33 +04:00
parent c1a6c69145
commit 21f2529e97
5 changed files with 61 additions and 6 deletions

View File

@ -49,6 +49,8 @@ namespace GameRes
private IEnumerable<AudioFormat> m_audio_formats; private IEnumerable<AudioFormat> m_audio_formats;
[ImportMany(typeof(ScriptFormat))] [ImportMany(typeof(ScriptFormat))]
private IEnumerable<ScriptFormat> m_script_formats; private IEnumerable<ScriptFormat> m_script_formats;
[ImportMany(typeof(ISettingsManager))]
private IEnumerable<ISettingsManager> m_settings_managers;
#pragma warning restore 649 #pragma warning restore 649
private MultiValueDictionary<string, IResource> m_extension_map = new MultiValueDictionary<string, IResource>(); private MultiValueDictionary<string, IResource> m_extension_map = new MultiValueDictionary<string, IResource>();
@ -107,11 +109,6 @@ namespace GameRes
} }
} }
public void SaveSettings ()
{
Properties.Settings.Default.Save();
}
private void AddResourceImpl (IEnumerable<IResource> formats, CompositionContainer container) private void AddResourceImpl (IEnumerable<IResource> formats, CompositionContainer container)
{ {
foreach (var impl in formats) foreach (var impl in formats)
@ -137,6 +134,29 @@ namespace GameRes
} }
} }
public void UpgradeSettings ()
{
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
foreach (var mgr in m_settings_managers)
{
mgr.UpgradeSettings();
}
}
public void SaveSettings ()
{
Properties.Settings.Default.Save();
foreach (var mgr in m_settings_managers)
{
mgr.SaveSettings();
}
}
/// <summary> /// <summary>
/// Look up filename in format registry by filename extension and return corresponding interfaces. /// Look up filename in format registry by filename extension and return corresponding interfaces.
/// if no formats available, return empty range. /// if no formats available, return empty range.
@ -320,7 +340,7 @@ namespace GameRes
} }
/// <summary> /// <summary>
/// Read text file <paramref name="filename"/> from data directory, performing <paramref name="process_line"/> action on each line. /// Read text file <paramref name="filename"/> from data directory, performing <paramref name="process_line"/> action on each non-empty line.
/// </summary> /// </summary>
public void ReadFileList (string filename, Action<string> process_line) public void ReadFileList (string filename, Action<string> process_line)
{ {

View File

@ -34,5 +34,17 @@ namespace GameRes.Properties {
this["BMPEnableExtensions"] = value; this["BMPEnableExtensions"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool UpgradeRequired {
get {
return ((bool)(this["UpgradeRequired"]));
}
set {
this["UpgradeRequired"] = value;
}
}
} }
} }

View File

@ -5,5 +5,8 @@
<Setting Name="BMPEnableExtensions" Type="System.Boolean" Scope="User"> <Setting Name="BMPEnableExtensions" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value> <Value Profile="(Default)">True</Value>
</Setting> </Setting>
<Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -52,6 +52,23 @@ namespace GameRes
object Value { get; set; } object Value { get; set; }
} }
/// <summary>
/// Manage assembly settings during application session. Implementations of this interface are made
/// available to GameRes library by means of MEF.
/// </summary>
public interface ISettingsManager
{
/// <summary>
/// Called on application startup to check if settings need upgrading after assembly version change.
/// </summary>
void UpgradeSettings ();
/// <summary>
/// Called on application exit.
/// </summary>
void SaveSettings ();
}
public abstract class ResourceSettingBase : IResourceSetting public abstract class ResourceSettingBase : IResourceSetting
{ {
public string Name { get; set; } public string Name { get; set; }

View File

@ -10,6 +10,9 @@
<setting name="BMPEnableExtensions" serializeAs="String"> <setting name="BMPEnableExtensions" serializeAs="String">
<value>True</value> <value>True</value>
</setting> </setting>
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
</GameRes.Properties.Settings> </GameRes.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>