aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Configuration')
-rw-r--r--MediaBrowser.Common/Configuration/ConfigurationHelper.cs68
-rw-r--r--MediaBrowser.Common/Configuration/IApplicationPaths.cs82
-rw-r--r--MediaBrowser.Common/Configuration/IConfigurationManager.cs36
3 files changed, 186 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs
new file mode 100644
index 000000000..fc74a6a4d
--- /dev/null
+++ b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs
@@ -0,0 +1,68 @@
+using MediaBrowser.Model.Serialization;
+using System;
+using System.IO;
+using System.Linq;
+
+namespace MediaBrowser.Common.Configuration
+{
+ /// <summary>
+ /// Class ConfigurationHelper
+ /// </summary>
+ public static class ConfigurationHelper
+ {
+ /// <summary>
+ /// Reads an xml configuration file from the file system
+ /// It will immediately re-serialize and save if new serialization data is available due to property changes
+ /// </summary>
+ /// <param name="type">The type.</param>
+ /// <param name="path">The path.</param>
+ /// <param name="xmlSerializer">The XML serializer.</param>
+ /// <returns>System.Object.</returns>
+ public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer)
+ {
+ object configuration;
+
+ byte[] buffer = null;
+
+ // Use try/catch to avoid the extra file system lookup using File.Exists
+ try
+ {
+ buffer = File.ReadAllBytes(path);
+
+ configuration = xmlSerializer.DeserializeFromBytes(type, buffer);
+ }
+ catch (FileNotFoundException)
+ {
+ configuration = Activator.CreateInstance(type);
+ }
+
+ // Take the object we just got and serialize it back to bytes
+ var newBytes = xmlSerializer.SerializeToBytes(configuration);
+
+ // If the file didn't exist before, or if something has changed, re-save
+ if (buffer == null || !buffer.SequenceEqual(newBytes))
+ {
+ // Save it after load in case we got new items
+ File.WriteAllBytes(path, newBytes);
+ }
+
+ return configuration;
+ }
+
+
+ /// <summary>
+ /// Reads an xml configuration file from the file system
+ /// It will immediately save the configuration after loading it, just
+ /// in case there are new serializable properties
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="path">The path.</param>
+ /// <param name="xmlSerializer">The XML serializer.</param>
+ /// <returns>``0.</returns>
+ public static T GetXmlConfiguration<T>(string path, IXmlSerializer xmlSerializer)
+ where T : class
+ {
+ return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T;
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Configuration/IApplicationPaths.cs b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
new file mode 100644
index 000000000..d2446ce46
--- /dev/null
+++ b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
@@ -0,0 +1,82 @@
+
+namespace MediaBrowser.Common.Configuration
+{
+ /// <summary>
+ /// Interface IApplicationPaths
+ /// </summary>
+ public interface IApplicationPaths
+ {
+ /// <summary>
+ /// Gets the path to the program data folder
+ /// </summary>
+ /// <value>The program data path.</value>
+ string ProgramDataPath { get; }
+
+ /// <summary>
+ /// Gets the path to the program system folder
+ /// </summary>
+ /// <value>The program data path.</value>
+ string ProgramSystemPath { get; }
+
+ /// <summary>
+ /// Gets the folder path to the data directory
+ /// </summary>
+ /// <value>The data directory.</value>
+ string DataPath { get; }
+
+ /// <summary>
+ /// Gets the image cache path.
+ /// </summary>
+ /// <value>The image cache path.</value>
+ string ImageCachePath { get; }
+
+ /// <summary>
+ /// Gets the path to the plugin directory
+ /// </summary>
+ /// <value>The plugins path.</value>
+ string PluginsPath { get; }
+
+ /// <summary>
+ /// Gets the path to the plugin configurations directory
+ /// </summary>
+ /// <value>The plugin configurations path.</value>
+ string PluginConfigurationsPath { get; }
+
+ /// <summary>
+ /// Gets the path to where temporary update files will be stored
+ /// </summary>
+ /// <value>The plugin configurations path.</value>
+ string TempUpdatePath { get; }
+
+ /// <summary>
+ /// Gets the path to the log directory
+ /// </summary>
+ /// <value>The log directory path.</value>
+ string LogDirectoryPath { get; }
+
+ /// <summary>
+ /// Gets the path to the application configuration root directory
+ /// </summary>
+ /// <value>The configuration directory path.</value>
+ string ConfigurationDirectoryPath { get; }
+
+ /// <summary>
+ /// Gets the path to the system configuration file
+ /// </summary>
+ /// <value>The system configuration file path.</value>
+ string SystemConfigurationFilePath { get; }
+
+ /// <summary>
+ /// Gets the folder path to the cache directory
+ /// </summary>
+ /// <value>The cache directory.</value>
+ string CachePath { get; }
+
+ /// <summary>
+ /// Gets the folder path to the temp directory within the cache folder
+ /// </summary>
+ /// <value>The temp directory.</value>
+ string TempDirectory { get; }
+ }
+
+}
diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
new file mode 100644
index 000000000..0d0759b66
--- /dev/null
+++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
@@ -0,0 +1,36 @@
+using MediaBrowser.Model.Configuration;
+using System;
+
+namespace MediaBrowser.Common.Configuration
+{
+ public interface IConfigurationManager
+ {
+ /// <summary>
+ /// Occurs when [configuration updated].
+ /// </summary>
+ event EventHandler<EventArgs> ConfigurationUpdated;
+
+ /// <summary>
+ /// Gets or sets the application paths.
+ /// </summary>
+ /// <value>The application paths.</value>
+ IApplicationPaths CommonApplicationPaths { get; }
+
+ /// <summary>
+ /// Gets the configuration.
+ /// </summary>
+ /// <value>The configuration.</value>
+ BaseApplicationConfiguration CommonConfiguration { get; }
+
+ /// <summary>
+ /// Saves the configuration.
+ /// </summary>
+ void SaveConfiguration();
+
+ /// <summary>
+ /// Replaces the configuration.
+ /// </summary>
+ /// <param name="newConfiguration">The new configuration.</param>
+ void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration);
+ }
+}