aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaronGreenback <jimcartlidge@yahoo.co.uk>2020-12-23 16:28:50 +0000
committerBaronGreenback <jimcartlidge@yahoo.co.uk>2020-12-23 16:28:50 +0000
commit62702fa3eb5070ce8c57dc4e39551bcc4e64fa74 (patch)
tree050374062fb5251c0bb2a09bb25427a625a8a109
parentd98f42a6aa80b4d9f5f9ffecc17f87bd2510442a (diff)
Changes as requested
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs2
-rw-r--r--Emby.Server.Implementations/Plugins/PluginManager.cs45
-rw-r--r--Jellyfin.Api/Controllers/PluginsController.cs16
-rw-r--r--Jellyfin.Api/Models/ConfigurationPageInfo.cs1
-rw-r--r--MediaBrowser.Common/Plugins/BasePluginOfT.cs20
-rw-r--r--MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs6
-rw-r--r--MediaBrowser.Common/Plugins/IPluginManager.cs1
-rw-r--r--MediaBrowser.Common/Plugins/PluginManifest.cs4
8 files changed, 43 insertions, 52 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index f73cd1ea4..b91ba6b6c 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -462,7 +462,7 @@ namespace Emby.Server.Implementations
{
// Convert to list so this isn't executed for each iteration
var parts = GetExportTypes<T>()
- .Select(defaultFunc)
+ .Select(i => defaultFunc(i))
.Where(i => i != null)
.Cast<T>()
.ToList();
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs
index 629975abb..c06359757 100644
--- a/Emby.Server.Implementations/Plugins/PluginManager.cs
+++ b/Emby.Server.Implementations/Plugins/PluginManager.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
+using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Json;
@@ -86,7 +87,8 @@ namespace Emby.Server.Implementations.Plugins
var plugin = _plugins[i];
if (plugin.Manifest.Status == PluginStatus.Deleted && DeletePlugin(plugin))
{
- UpdateSuccessors(plugin);
+ // See if there is another version, and if so make that active.
+ ProcessAlternative(plugin);
}
}
@@ -208,12 +210,19 @@ namespace Emby.Server.Implementations.Plugins
if (DeletePlugin(plugin))
{
+ ProcessAlternative(plugin);
return true;
}
_logger.LogWarning("Unable to delete {Path}, so marking as deleteOnStartup.", plugin.Path);
// Unable to delete, so disable.
- return ChangePluginState(plugin, PluginStatus.Deleted);
+ if (ChangePluginState(plugin, PluginStatus.Deleted))
+ {
+ ProcessAlternative(plugin);
+ return true;
+ }
+
+ return false;
}
/// <summary>
@@ -232,9 +241,9 @@ namespace Emby.Server.Implementations.Plugins
var plugins = _plugins.Where(p => p.Id.Equals(id)).ToList();
plugin = plugins.FirstOrDefault(p => p.Instance != null);
- if (plugin == null && plugins.Length > 0)
+ if (plugin == null)
{
- plugin = plugins.OrderByDescending(p => p.Version)[0];
+ plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault();
}
}
else
@@ -259,7 +268,8 @@ namespace Emby.Server.Implementations.Plugins
if (ChangePluginState(plugin, PluginStatus.Active))
{
- UpdateSuccessors(plugin);
+ // See if there is another version, and if so, supercede it.
+ ProcessAlternative(plugin);
}
}
@@ -277,7 +287,8 @@ namespace Emby.Server.Implementations.Plugins
// Update the manifest on disk
if (ChangePluginState(plugin, PluginStatus.Disabled))
{
- UpdateSuccessors(plugin);
+ // If there is another version, activate it.
+ ProcessAlternative(plugin);
}
}
@@ -639,27 +650,33 @@ namespace Emby.Server.Implementations.Plugins
/// 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)
+ private void ProcessAlternative(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)
+ var previousVersion = _plugins.OrderByDescending(p => p.Version)
.FirstOrDefault(
p => p.Id.Equals(plugin.Id)
&& p.IsEnabledAndSupported
&& p.Version != plugin.Version);
- if (predecessor == null)
+ if (previousVersion == null)
{
+ // This value is memory only - so that the web will show restart required.
+ plugin.Manifest.Status = PluginStatus.Restart;
return;
}
- if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded))
+ if (plugin.Manifest.Status == PluginStatus.Active && !ChangePluginState(previousVersion, PluginStatus.Superceded))
+ {
+ _logger.LogError("Unable to enable version {Version} of {Name}", previousVersion.Version, previousVersion.Name);
+ }
+ else if (plugin.Manifest.Status == PluginStatus.Superceded && !ChangePluginState(previousVersion, PluginStatus.Active))
{
- _logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name);
+ _logger.LogError("Unable to supercede version {Version} of {Name}", previousVersion.Version, previousVersion.Name);
}
+
+ // This value is memory only - so that the web will show restart required.
+ plugin.Manifest.Status = PluginStatus.Restart;
}
}
}
diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs
index 365bb2248..b73611c97 100644
--- a/Jellyfin.Api/Controllers/PluginsController.cs
+++ b/Jellyfin.Api/Controllers/PluginsController.cs
@@ -198,7 +198,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="pluginId">Plugin id.</param>
/// <response code="204">Plugin uninstalled.</response>
/// <response code="404">Plugin not found.</response>
- /// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
+ /// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the plugin could not be found.</returns>
[HttpDelete("{pluginId}")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
@@ -210,7 +210,7 @@ namespace Jellyfin.Api.Controllers
var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId));
// Select the un-instanced one first.
- var plugin = plugins.FirstOrDefault(p => p.Instance != null);
+ var plugin = plugins.FirstOrDefault(p => p.Instance == null);
if (plugin == null)
{
// Then by the status.
@@ -256,11 +256,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="pluginId">Plugin id.</param>
/// <response code="204">Plugin configuration updated.</response>
/// <response code="404">Plugin not found or plugin does not have configuration.</response>
- /// <returns>
- /// A <see cref="Task" /> that represents the asynchronous operation to update plugin configuration.
- /// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
- /// when plugin not found or plugin doesn't have configuration.
- /// </returns>
+ /// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the plugin could not be found.</returns>
[HttpPost("{pluginId}/Configuration")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
@@ -321,11 +317,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="pluginId">Plugin id.</param>
/// <response code="204">Plugin manifest returned.</response>
/// <response code="404">Plugin not found.</response>
- /// <returns>
- /// A <see cref="Task" /> that represents the asynchronous operation to get the plugin's manifest.
- /// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
- /// when plugin not found.
- /// </returns>
+ /// <returns>A <see cref="PluginManifest"/> on success, or a <see cref="NotFoundResult"/> if the plugin could not be found.</returns>
[HttpPost("{pluginId}/Manifest")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
diff --git a/Jellyfin.Api/Models/ConfigurationPageInfo.cs b/Jellyfin.Api/Models/ConfigurationPageInfo.cs
index c15ed05d3..f56ef5976 100644
--- a/Jellyfin.Api/Models/ConfigurationPageInfo.cs
+++ b/Jellyfin.Api/Models/ConfigurationPageInfo.cs
@@ -23,7 +23,6 @@ namespace Jellyfin.Api.Models
if (page.Plugin != null)
{
DisplayName = page.Plugin.Name;
- // Don't use "N" because it needs to match Plugin.Id
PluginId = page.Plugin.Id;
}
}
diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
index ea05a722b..d5c780851 100644
--- a/MediaBrowser.Common/Plugins/BasePluginOfT.cs
+++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
@@ -25,8 +25,6 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
private readonly object _configurationSaveLock = new object();
- private Action<string> _directoryCreateFn;
-
/// <summary>
/// The configuration.
/// </summary>
@@ -65,11 +63,6 @@ namespace MediaBrowser.Common.Plugins
assemblyPlugin.SetId(assemblyId);
}
}
-
- if (this is IHasPluginConfiguration hasPluginConfiguration)
- {
- hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s));
- }
}
/// <summary>
@@ -145,13 +138,6 @@ namespace MediaBrowser.Common.Plugins
/// <value>The configuration.</value>
BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration;
- /// <inheritdoc />
- public void SetStartupInfo(Action<string> directoryCreateFn)
- {
- // hack alert, until the .net core transition is complete
- _directoryCreateFn = directoryCreateFn;
- }
-
/// <summary>
/// Saves the current configuration to the file system.
/// </summary>
@@ -160,7 +146,11 @@ namespace MediaBrowser.Common.Plugins
{
lock (_configurationSaveLock)
{
- _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath));
+ var folder = Path.GetDirectoryName(ConfigurationFilePath);
+ if (!Directory.Exists(folder))
+ {
+ Directory.CreateDirectory(folder);
+ }
XmlSerializer.SerializeToFile(config, ConfigurationFilePath);
}
diff --git a/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs
index 42ad85dd3..af9272caa 100644
--- a/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs
+++ b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs
@@ -23,11 +23,5 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
/// <param name="configuration">The configuration.</param>
void UpdateConfiguration(BasePluginConfiguration configuration);
-
- /// <summary>
- /// Sets the startup directory creation function.
- /// </summary>
- /// <param name="directoryCreateFn">The directory function used to create the configuration folder.</param>
- void SetStartupInfo(Action<string> directoryCreateFn);
}
}
diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs
index 7f7381b03..3da34d8bb 100644
--- a/MediaBrowser.Common/Plugins/IPluginManager.cs
+++ b/MediaBrowser.Common/Plugins/IPluginManager.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
+using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs
index 334c8d908..4c724f694 100644
--- a/MediaBrowser.Common/Plugins/PluginManifest.cs
+++ b/MediaBrowser.Common/Plugins/PluginManifest.cs
@@ -19,14 +19,12 @@ namespace MediaBrowser.Common.Plugins
Category = string.Empty;
Changelog = string.Empty;
Description = string.Empty;
- Status = PluginStatus.Active;
Id = Guid.Empty;
Name = string.Empty;
Owner = string.Empty;
Overview = string.Empty;
TargetAbi = string.Empty;
Version = string.Empty;
- AutoUpdate = true;
}
/// <summary>
@@ -99,7 +97,7 @@ namespace MediaBrowser.Common.Plugins
/// Gets or sets a value indicating whether this plugin should automatically update.
/// </summary>
[JsonPropertyName("autoUpdate")]
- public bool AutoUpdate { get; set; }
+ public bool AutoUpdate { get; set; } = true; // DO NOT MOVE THIS INTO THE CONSTRUCTOR.
/// <summary>
/// Gets or sets the ImagePath