From 5a3efc526631b7f774b17ea5a8a54130696b6e25 Mon Sep 17 00:00:00 2001 From: Greenback Date: Fri, 18 Dec 2020 09:04:40 +0000 Subject: [PATCH] Changes as required. --- .../ApplicationHost.cs | 3 +- .../Plugins/PluginManager.cs | 102 +++++++----------- MediaBrowser.Common/Plugins/BasePlugin.cs | 41 +------ 3 files changed, 42 insertions(+), 104 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 216cb5e758..d7bc83f3a5 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -35,6 +35,7 @@ using Emby.Server.Implementations.LiveTv; using Emby.Server.Implementations.Localization; using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Playlists; +using Emby.Server.Implementations.Plugins; using Emby.Server.Implementations.QuickConnect; using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; @@ -281,7 +282,7 @@ namespace Emby.Server.Implementations ApplicationUserAgent = Name.Replace(' ', '-') + "/" + ApplicationVersionString; _pluginManager = new PluginManager( - LoggerFactory, + LoggerFactory.CreateLogger(), this, ServerConfigurationManager.Configuration, ApplicationPaths.PluginsPath, diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 2e4b23bcf8..151e2c2036 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.Plugins /// /// Initializes a new instance of the class. /// - /// The . + /// The . /// The . /// The . /// The plugin path. @@ -49,13 +49,12 @@ namespace Emby.Server.Implementations.Plugins string imagesPath, Version appVersion) { - _logger = loggerfactory.CreateLogger(); + _logger = _logger ?? throw new ArgumentNullException(nameof(logger)); _pluginsPath = pluginsPath; _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); - _jsonOptions = JsonDefaults.GetCamelCaseOptions(); + _jsonOptions = JsonDefaults.GetOptions(); _config = config; _appHost = appHost; - _imagesPath = imagesPath; _nextVersion = new Version(_appVersion.Major, _appVersion.Minor + 2, _appVersion.Build, _appVersion.Revision); _minimumVersion = new Version(0, 0, 0, 1); _plugins = Directory.Exists(_pluginsPath) ? DiscoverPlugins().ToList() : new List(); @@ -273,62 +272,6 @@ namespace Emby.Server.Implementations.Plugins } } - private void CopyFiles(string source, string destination, bool overwrite, string searchPattern) - { - FileInfo[] files; - try - { - files = new DirectoryInfo(source).GetFiles(searchPattern); - } - catch (Exception ex) - { - _logger.LogDebug(ex, "Error retrieving file list."); - return; - } - - foreach (FileInfo file in files) - { - try - { - file.CopyTo(Path.Combine(destination, file.Name), overwrite); - } - catch (Exception ex) - { - _logger.LogDebug(ex, "Error copying file {Name}", file.Name); - } - } - } - - /// - /// Changes the status of the other versions of the plugin to "Superceded". - /// - /// The that's master. - private void UpdateSuccessors(LocalPlugin plugin) - { - // This value is memory only - so that the web will show restart required. - plugin.Manifest.Status = PluginStatus.Restart; - - // Detect whether there is another version of this plugin that needs disabling. - var predecessor = _plugins.OrderByDescending(p => p.Version) - .FirstOrDefault( - p => p.Id.Equals(plugin.Id) - && p.IsEnabledAndSupported - && p.Version != plugin.Version); - - if (predecessor == null) - { - return; - } - - // migrate settings across from the last active version if they don't exist. - CopyFiles(predecessor.Path, plugin.Path, false, "*.xml"); - - if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded)) - { - _logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name); - } - } - /// /// Disable the plugin. /// @@ -429,19 +372,19 @@ namespace Emby.Server.Implementations.Plugins if (plugin == null) { // Create a dummy record for the providers. + // TODO: remove this code, if all provided have been released as separate plugins. plugin = new LocalPlugin( - pInstance.AssemblyFilePath, + instance.AssemblyFilePath, true, new PluginManifest { - Guid = pInstance.Id, + Guid = instance.Id, Status = PluginStatus.Active, - Name = pInstance.Name, - Version = pInstance.Version.ToString(), - MaxAbi = _nextVersion.ToString() + Name = instance.Name, + Version = instance.Version.ToString() }) { - Instance = pInstance + Instance = instance }; _plugins.Add(plugin); @@ -707,5 +650,32 @@ namespace Emby.Server.Implementations.Plugins // Only want plugin folders which have files. return versions.Where(p => p.DllFiles.Count != 0); } + + /// + /// Changes the status of the other versions of the plugin to "Superceded". + /// + /// The that's master. + private void UpdateSuccessors(LocalPlugin plugin) + { + // This value is memory only - so that the web will show restart required. + plugin.Manifest.Status = PluginStatus.Restart; + + // Detect whether there is another version of this plugin that needs disabling. + var predecessor = _plugins.OrderByDescending(p => p.Version) + .FirstOrDefault( + p => p.Id.Equals(plugin.Id) + && p.IsEnabledAndSupported + && p.Version != plugin.Version); + + if (predecessor == null) + { + return; + } + + if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded)) + { + _logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name); + } + } } } diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 5756f8852c..5750c59c42 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -134,25 +134,11 @@ namespace MediaBrowser.Common.Plugins var assemblyName = assembly.GetName(); var assemblyFilePath = assembly.Location; - // Find out the plugin folder. - bool inPluginFolder = assemblyFilePath.StartsWith(ApplicationPaths.PluginsPath, StringComparison.OrdinalIgnoreCase); - string path, dataFolderPath; - - var configurationFileName = Path.ChangeExtension(Path.GetFileName(assemblyFilePath), ".xml"); - if (inPluginFolder) - { - // Normal plugin. - path = assemblyFilePath.Substring(ApplicationPaths.PluginsPath.Length).Split('\\', StringSplitOptions.RemoveEmptyEntries)[0]; - dataFolderPath = Path.Combine( - Path.Combine(ApplicationPaths.PluginsPath, path), - configurationFileName); - ConfigurationFilePath = dataFolderPath; - } - else + var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath)); + if (!Directory.Exists(dataFolderPath)) { - // Provider - dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath)); - ConfigurationFilePath = Path.Combine(ApplicationPaths.PluginConfigurationsPath, configurationFileName); + // Try again with the version number appended to the folder name. + dataFolderPath = dataFolderPath + "_" + Version.ToString(); } assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version); @@ -165,25 +151,6 @@ namespace MediaBrowser.Common.Plugins assemblyPlugin.SetId(assemblyId); } - - // TODO : Remove this, once migration support is ceased. - if (inPluginFolder) - { - var oldConfigFilePath = Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName); - - if (!File.Exists(ConfigurationFilePath) && File.Exists(oldConfigFilePath)) - { - // Migrate pre 10.7 settings, as different plugin versions may have different settings. - try - { - File.Copy(oldConfigFilePath, ConfigurationFilePath); - } - catch - { - // Unable to migrate settings. - } - } - } } if (this is IHasPluginConfiguration hasPluginConfiguration)