From 6e8bfb6d9b34e8aad876bdb21907ca686741e7cb Mon Sep 17 00:00:00 2001 From: ebr11 Eric Reed spam Date: Wed, 1 Aug 2012 23:13:44 -0400 Subject: Add ApplicationPaths class --- MediaBrowser.Common/Kernel/BaseKernel.cs | 123 +++++++------------------------ 1 file changed, 26 insertions(+), 97 deletions(-) (limited to 'MediaBrowser.Common/Kernel/BaseKernel.cs') diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index cc3cb76f0..514c05097 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -21,49 +21,6 @@ namespace MediaBrowser.Common.Kernel public abstract class BaseKernel : IDisposable where TConfigurationType : BaseApplicationConfiguration, new() { - /// - /// Gets the path to the program data folder - /// - public string ProgramDataPath { get; private set; } - - /// - /// Gets the path to the plugin directory - /// - protected string PluginsPath - { - get - { - return Path.Combine(ProgramDataPath, "plugins"); - } - } - - /// - /// Gets the path to the application configuration file - /// - protected string ConfigurationPath - { - get - { - return Path.Combine(ProgramDataPath, "config.js"); - } - } - - /// - /// Gets the path to the log directory - /// - private string LogDirectoryPath - { - get - { - return Path.Combine(ProgramDataPath, "logs"); - } - } - - /// - /// Gets or sets the path to the current log file - /// - private string LogFilePath { get; set; } - /// /// Gets the current configuration /// @@ -88,7 +45,7 @@ namespace MediaBrowser.Common.Kernel public BaseKernel() { - ProgramDataPath = GetProgramDataPath(); + } public virtual void Init(IProgress progress) @@ -102,18 +59,18 @@ namespace MediaBrowser.Common.Kernel ReloadComposableParts(); } + /// + /// Gets or sets the path to the current log file + /// + public static string LogFilePath { get; set; } + private void ReloadLogger() { DisposeLogger(); - if (!Directory.Exists(LogDirectoryPath)) - { - Directory.CreateDirectory(LogDirectoryPath); - } - DateTime now = DateTime.Now; - LogFilePath = Path.Combine(LogDirectoryPath, now.ToString("dMyyyy") + "-" + now.Ticks + ".log"); + LogFilePath = Path.Combine(ApplicationPaths.LogDirectoryPath, Assembly.GetExecutingAssembly().GetType().Name + "-" + now.ToString("dMyyyy") + "-" + now.Ticks + ".log"); FileStream fs = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read); @@ -126,14 +83,9 @@ namespace MediaBrowser.Common.Kernel /// protected void ReloadComposableParts() { - if (!Directory.Exists(PluginsPath)) - { - Directory.CreateDirectory(PluginsPath); - } - // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that // This will prevent the .dll file from getting locked, and allow us to replace it when needed - IEnumerable pluginAssemblies = Directory.GetFiles(PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f)))); + IEnumerable pluginAssemblies = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f)))); var catalog = new AggregateCatalog(pluginAssemblies.Select(a => new AssemblyCatalog(a))); //catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); @@ -172,7 +124,7 @@ namespace MediaBrowser.Common.Kernel AssemblyName assemblyName = assembly.GetName(); plugin.Version = assemblyName.Version; - plugin.Path = Path.Combine(PluginsPath, assemblyName.Name); + plugin.Path = Path.Combine(ApplicationPaths.PluginsPath, assemblyName.Name); plugin.Context = KernelContext; @@ -185,57 +137,34 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Gets the path to the application's ProgramDataFolder - /// - private string GetProgramDataPath() - { - string programDataPath = ConfigurationManager.AppSettings["ProgramDataPath"]; - - // If it's a relative path, e.g. "..\" - if (!Path.IsPathRooted(programDataPath)) - { - string path = Assembly.GetExecutingAssembly().Location; - path = Path.GetDirectoryName(path); - - programDataPath = Path.Combine(path, programDataPath); - - programDataPath = Path.GetFullPath(programDataPath); - } - - if (!Directory.Exists(programDataPath)) - { - Directory.CreateDirectory(programDataPath); - } - - return programDataPath; - } /// /// Reloads application configuration from the config file /// private void ReloadConfiguration() { - // Deserialize config - if (!File.Exists(ConfigurationPath)) - { - Configuration = new TConfigurationType(); - } - else - { - Configuration = JsonSerializer.DeserializeFromFile(ConfigurationPath); - } + //Configuration information for anything other than server-specific configuration will have to come via the API... -ebr - Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity; + //// Deserialize config + //if (!File.Exists(ConfigurationPath)) + //{ + // Configuration = new TConfigurationType(); + //} + //else + //{ + // Configuration = JsonSerializer.DeserializeFromFile(ConfigurationPath); + //} + + //Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity; } /// /// Saves the current application configuration to the config file /// - public void SaveConfiguration() - { - JsonSerializer.SerializeToFile(Configuration, ConfigurationPath); - } + //public void SaveConfiguration() + //{ + // JsonSerializer.SerializeToFile(Configuration, ConfigurationPath); + //} /// /// Restarts the Http Server, or starts it if not currently running @@ -255,7 +184,7 @@ namespace MediaBrowser.Common.Kernel AssemblyName assemblyName = new AssemblyName(args.Name); // Look for the .dll recursively within the plugins directory - string dll = Directory.GetFiles(PluginsPath, "*.dll", SearchOption.AllDirectories) + string dll = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories) .FirstOrDefault(f => Path.GetFileNameWithoutExtension(f) == assemblyName.Name); // If we found a matching assembly, load it now -- cgit v1.2.3