aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreenback <jimcartlidge@yahoo.co.uk>2020-12-15 00:42:59 +0000
committerGreenback <jimcartlidge@yahoo.co.uk>2020-12-15 00:42:59 +0000
commitfbb20ebef6dee03de27e20d7e110e709ba2f20e9 (patch)
tree4eeaf08c92cfb714c45e7a6a1c320bfde0cfc1a7
parent494ace7984edab77df7f9da30e411d8d3d617036 (diff)
Plugin setting migration to folders.
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs5
-rw-r--r--Emby.Server.Implementations/Plugins/PluginManager.cs11
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs42
3 files changed, 50 insertions, 8 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 8df1ec300..ddb48ff6e 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -406,10 +406,7 @@ namespace Emby.Server.Implementations
Logger.LogError("Called from: {stack}", entry.FullName);
}
- if (type is IPlugin)
- {
- _pluginManager.FailPlugin(type.Assembly);
- }
+ _pluginManager.FailPlugin(type.Assembly);
throw new ExternalException("DI Loop detected.");
}
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs
index 1377c80ea..07b729748 100644
--- a/Emby.Server.Implementations/Plugins/PluginManager.cs
+++ b/Emby.Server.Implementations/Plugins/PluginManager.cs
@@ -296,7 +296,7 @@ namespace Emby.Server.Implementations
return;
}
- if (!ChangePluginState(predecessor, PluginStatus.Superceded))
+ if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded))
{
_logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name);
}
@@ -314,7 +314,10 @@ namespace Emby.Server.Implementations
throw new ArgumentNullException(nameof(assembly));
}
- var plugin = _plugins.Where(p => assembly.Equals(p.Assembly)).FirstOrDefault();
+ var plugin = _plugins.Where(
+ p => assembly.Equals(p.Assembly)
+ || string.Equals(assembly.Location, assembly.Location, StringComparison.OrdinalIgnoreCase))
+ .FirstOrDefault();
if (plugin == null)
{
// A plugin's assembly didn't cause this issue, so ignore it.
@@ -403,6 +406,10 @@ namespace Emby.Server.Implementations
{
// Find the record for this plugin.
var plugin = GetPluginByType(type);
+ if (plugin?.Manifest.Status < PluginStatus.Active)
+ {
+ return null;
+ }
try
{
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index b918fc4f6..a0d6b8f83 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -134,7 +134,26 @@ namespace MediaBrowser.Common.Plugins
var assemblyName = assembly.GetName();
var assemblyFilePath = assembly.Location;
- var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
+ // 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
+ {
+ // Provider
+ dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
+ ConfigurationFilePath = Path.Combine(ApplicationPaths.PluginConfigurationsPath, configurationFileName);
+ }
assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version);
@@ -146,6 +165,25 @@ namespace MediaBrowser.Common.Plugins
assemblyPlugin.SetId(assemblyId);
}
+
+ // TODO : Simplify this, once migration support is ceased.
+ if (inPluginFolder)
+ {
+ var oldConfigFilePath = Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
+
+ if (!File.Exists(ConfigurationFilePath) && File.Exists(oldConfigFilePath))
+ {
+ // Migrate settings, as different plugin versions may have different settings.
+ try
+ {
+ File.Copy(oldConfigFilePath, ConfigurationFilePath);
+ }
+ catch
+ {
+ // Unable to migrate settings.
+ }
+ }
+ }
}
if (this is IHasPluginConfiguration hasPluginConfiguration)
@@ -219,7 +257,7 @@ namespace MediaBrowser.Common.Plugins
/// Gets the full path to the configuration file.
/// </summary>
/// <value>The configuration file path.</value>
- public string ConfigurationFilePath => Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
+ public string ConfigurationFilePath { get; }
/// <summary>
/// Gets the plugin configuration.