From 4390e2f7108f24f89a1bf7ef9f6f7c9c57b4f221 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 23 Apr 2013 15:17:21 -0400 Subject: #35 - Make IBN path configurable --- .../Configuration/ServerConfigurationManager.cs | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index cb4c5a6cd..bdc4fcf45 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Configuration; +using System.IO; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Implementations.Configuration; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -23,6 +24,7 @@ namespace MediaBrowser.Server.Implementations.Configuration public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer) : base(applicationPaths, logManager, xmlSerializer) { + UpdateItemsByNamePath(); } /// @@ -51,5 +53,47 @@ namespace MediaBrowser.Server.Implementations.Configuration { get { return (ServerConfiguration)CommonConfiguration; } } + + /// + /// Called when [configuration updated]. + /// + protected override void OnConfigurationUpdated() + { + UpdateItemsByNamePath(); + + base.OnConfigurationUpdated(); + } + + /// + /// Updates the items by name path. + /// + private void UpdateItemsByNamePath() + { + if (!string.IsNullOrEmpty(Configuration.ItemsByNamePath)) + { + ApplicationPaths.ItemsByNamePath = Configuration.ItemsByNamePath; + } + } + + /// + /// Replaces the configuration. + /// + /// The new configuration. + /// + public override void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration) + { + var newConfig = (ServerConfiguration) newConfiguration; + + if (!string.Equals(Configuration.ItemsByNamePath, newConfig.ItemsByNamePath)) + { + // Validate + if (!Directory.Exists(newConfig.ItemsByNamePath)) + { + throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newConfig.ItemsByNamePath)); + } + } + + base.ReplaceConfiguration(newConfiguration); + } } } -- cgit v1.2.3