diff options
author | Lukasz <lukaszunity@users.noreply.github.com> | 2016-01-19 13:10:14 +0300 |
---|---|---|
committer | Lukasz <lukaszunity@users.noreply.github.com> | 2016-01-28 10:41:02 +0300 |
commit | f4671e42211b48471c57d2f069104ba88ea34a5c (patch) | |
tree | 0562b8b5ada1f7f87bfbb5e0fe274be1d85d6bcc /Mono.Addins/Mono.Addins.Database | |
parent | 60d87622dc6fe6b30913a1730f2f0c205363f2bb (diff) |
[addins-database] Add support for application level add-ins config file.
Allows applications to disable shipped add-ins by default.
Diffstat (limited to 'Mono.Addins/Mono.Addins.Database')
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinDatabase.cs | 2 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs | 32 |
2 files changed, 29 insertions, 5 deletions
diff --git a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs index 3201c0e..32939b8 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs @@ -1812,7 +1812,7 @@ namespace Mono.Addins.Database if (fileDatabase.Exists (ConfigFile)) config = DatabaseConfiguration.Read (ConfigFile); else - config = new DatabaseConfiguration (); + config = DatabaseConfiguration.ReadAppConfig (); } } return config; diff --git a/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs b/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs index 77270bf..e386802 100644 --- a/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs +++ b/Mono.Addins/Mono.Addins.Database/DatabaseConfiguration.cs @@ -76,10 +76,6 @@ namespace Mono.Addins.Database AddinStatus s; addinStatus.TryGetValue (addinName, out s); - if (enabled == defaultValue) { - addinStatus.Remove (addinName); - return; - } if (s == null) s = addinStatus [addinName] = new AddinStatus (addinName); s.Enabled = enabled; @@ -121,6 +117,34 @@ namespace Mono.Addins.Database public static DatabaseConfiguration Read (string file) { + var config = ReadInternal (file); + // Try to read application level config to support disabling add-ins by default. + var appConfig = ReadAppConfig (); + + if (appConfig == null) + return config; + + // Overwrite app config values with user config values + foreach (var entry in config.addinStatus) + appConfig.addinStatus [entry.Key] = entry.Value; + + return appConfig; + } + + public static DatabaseConfiguration ReadAppConfig() + { + var exePath = System.Reflection.Assembly.GetExecutingAssembly ().Location; + var exeDirectory = Path.GetDirectoryName (exePath); + var appAddinsConfigFilePath = Path.Combine (exeDirectory, "addins-config.xml"); + + if (!File.Exists (appAddinsConfigFilePath)) + return new DatabaseConfiguration (); + + return ReadInternal (appAddinsConfigFilePath); + } + + static DatabaseConfiguration ReadInternal (string file) + { DatabaseConfiguration config = new DatabaseConfiguration (); XmlDocument doc = new XmlDocument (); doc.Load (file); |