From 21f2529e97df51dd775093fe16d059e378010b1d Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 11 Jan 2018 18:38:33 +0400 Subject: [PATCH] (ISettingsManager): new public interface. --- GameRes/FormatCatalog.cs | 32 ++++++++++++++++++++----- GameRes/Properties/Settings.Designer.cs | 12 ++++++++++ GameRes/Properties/Settings.settings | 3 +++ GameRes/ResourceSettings.cs | 17 +++++++++++++ GameRes/app.config | 3 +++ 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/GameRes/FormatCatalog.cs b/GameRes/FormatCatalog.cs index 8d62ee28..eebedb7e 100644 --- a/GameRes/FormatCatalog.cs +++ b/GameRes/FormatCatalog.cs @@ -49,6 +49,8 @@ namespace GameRes private IEnumerable m_audio_formats; [ImportMany(typeof(ScriptFormat))] private IEnumerable m_script_formats; + [ImportMany(typeof(ISettingsManager))] + private IEnumerable m_settings_managers; #pragma warning restore 649 private MultiValueDictionary m_extension_map = new MultiValueDictionary(); @@ -107,11 +109,6 @@ namespace GameRes } } - public void SaveSettings () - { - Properties.Settings.Default.Save(); - } - private void AddResourceImpl (IEnumerable formats, CompositionContainer container) { 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(); + } + } + /// /// Look up filename in format registry by filename extension and return corresponding interfaces. /// if no formats available, return empty range. @@ -320,7 +340,7 @@ namespace GameRes } /// - /// Read text file from data directory, performing action on each line. + /// Read text file from data directory, performing action on each non-empty line. /// public void ReadFileList (string filename, Action process_line) { diff --git a/GameRes/Properties/Settings.Designer.cs b/GameRes/Properties/Settings.Designer.cs index 0c57d68a..b147338a 100644 --- a/GameRes/Properties/Settings.Designer.cs +++ b/GameRes/Properties/Settings.Designer.cs @@ -34,5 +34,17 @@ namespace GameRes.Properties { 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; + } + } } } diff --git a/GameRes/Properties/Settings.settings b/GameRes/Properties/Settings.settings index 52b5370a..549aaf77 100644 --- a/GameRes/Properties/Settings.settings +++ b/GameRes/Properties/Settings.settings @@ -5,5 +5,8 @@ True + + True + \ No newline at end of file diff --git a/GameRes/ResourceSettings.cs b/GameRes/ResourceSettings.cs index 233cd9f2..cd021fa7 100644 --- a/GameRes/ResourceSettings.cs +++ b/GameRes/ResourceSettings.cs @@ -52,6 +52,23 @@ namespace GameRes object Value { get; set; } } + /// + /// Manage assembly settings during application session. Implementations of this interface are made + /// available to GameRes library by means of MEF. + /// + public interface ISettingsManager + { + /// + /// Called on application startup to check if settings need upgrading after assembly version change. + /// + void UpgradeSettings (); + + /// + /// Called on application exit. + /// + void SaveSettings (); + } + public abstract class ResourceSettingBase : IResourceSetting { public string Name { get; set; } diff --git a/GameRes/app.config b/GameRes/app.config index c5e2a39c..e9cd7531 100644 --- a/GameRes/app.config +++ b/GameRes/app.config @@ -10,6 +10,9 @@ True + + True + \ No newline at end of file