Changes as required.

pull/4709/head
Greenback 4 years ago
parent 4153551dfc
commit 5a3efc5266

@ -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<PluginManager>(),
this,
ServerConfigurationManager.Configuration,
ApplicationPaths.PluginsPath,

@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.Plugins
/// <summary>
/// Initializes a new instance of the <see cref="PluginManager"/> class.
/// </summary>
/// <param name="loggerfactory">The <see cref="ILoggerFactory"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
/// <param name="appHost">The <see cref="IApplicationHost"/>.</param>
/// <param name="config">The <see cref="ServerConfiguration"/>.</param>
/// <param name="pluginsPath">The plugin path.</param>
@ -49,13 +49,12 @@ namespace Emby.Server.Implementations.Plugins
string imagesPath,
Version appVersion)
{
_logger = loggerfactory.CreateLogger<PluginManager>();
_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<LocalPlugin>();
@ -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);
}
}
}
/// <summary>
/// Changes the status of the other versions of the plugin to "Superceded".
/// </summary>
/// <param name="plugin">The <see cref="LocalPlugin"/> that's master.</param>
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);
}
}
/// <summary>
/// Disable the plugin.
/// </summary>
@ -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);
}
/// <summary>
/// Changes the status of the other versions of the plugin to "Superceded".
/// </summary>
/// <param name="plugin">The <see cref="LocalPlugin"/> that's master.</param>
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);
}
}
}
}

@ -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)

Loading…
Cancel
Save