diff options
| author | Greenback <jimcartlidge@yahoo.co.uk> | 2020-12-15 20:27:42 +0000 |
|---|---|---|
| committer | Greenback <jimcartlidge@yahoo.co.uk> | 2020-12-15 20:27:42 +0000 |
| commit | 532388754053957a1b3066900b7b54e1894206f3 (patch) | |
| tree | 6ddc017eeb71c09fa5c43dc79c99ef1fb7c1c78a | |
| parent | 0337e39bae80ba78d19821373603f19bd6a5a95f (diff) | |
Replaced TryGetPlugin with GetPlugin
4 files changed, 32 insertions, 25 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 944b74652..26a029f71 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -212,12 +212,13 @@ namespace Emby.Server.Implementations /// <summary> /// Attempts to find the plugin with and id of <paramref name="id"/>. /// </summary> - /// <param name="id">Id of plugin.</param> - /// <param name="version">The version of the plugin to locate.</param> - /// <param name="plugin">A <see cref="LocalPlugin"/> if found, otherwise null.</param> - /// <returns>Boolean value signifying the success of the search.</returns> - public bool TryGetPlugin(Guid id, Version? version, out LocalPlugin? plugin) + /// <param name="id">The <see cref="Guid"/> of plugin.</param> + /// <param name="version">Optional <see cref="Version"/> of the plugin to locate.</param> + /// <returns>A <see cref="LocalPlugin"/> if located, or null if not.</returns> + public LocalPlugin? GetPlugin(Guid id, Version? version = null) { + LocalPlugin? plugin; + if (version == null) { // If no version is given, return the current instance. @@ -235,7 +236,7 @@ namespace Emby.Server.Implementations plugin = _plugins.FirstOrDefault(p => p.Id.Equals(id) && p.Version.Equals(version)); } - return plugin != null; + return plugin; } /// <summary> diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index fc80bdd75..7cab77c85 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -197,10 +197,11 @@ namespace Emby.Server.Implementations.Updates { var version = package.Versions[i]; + var plugin = _pluginManager.GetPlugin(packageGuid, version.VersionNumber); // Update the manifests, if anything changes. - if (_pluginManager.TryGetPlugin(packageGuid, version.VersionNumber, out LocalPlugin? plugin)) + if (plugin != null) { - bool noChange = string.Equals(plugin!.Manifest.MaxAbi, version.MaxAbi, StringComparison.Ordinal) + bool noChange = string.Equals(plugin.Manifest.MaxAbi, version.MaxAbi, StringComparison.Ordinal) || string.Equals(plugin.Manifest.TargetAbi, version.TargetAbi, StringComparison.Ordinal); if (!noChange) { diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index b5976fbbd..49ccac137 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -134,12 +134,13 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - _pluginManager.EnablePlugin(plugin!); + _pluginManager.EnablePlugin(plugin); return NoContent(); } @@ -157,12 +158,13 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - _pluginManager.DisablePlugin(plugin!); + _pluginManager.DisablePlugin(plugin); return NoContent(); } @@ -180,7 +182,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult UninstallPluginByVersion([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } @@ -230,8 +233,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult<BasePluginConfiguration> GetPluginConfiguration([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin) - && plugin!.Instance is IHasPluginConfiguration configPlugin) + var plugin = _pluginManager.GetPlugin(pluginId); + if (plugin?.Instance is IHasPluginConfiguration configPlugin) { return configPlugin.Configuration; } @@ -258,8 +261,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task<ActionResult> UpdatePluginConfiguration([FromRoute, Required] Guid pluginId) { - if (!_pluginManager.TryGetPlugin(pluginId, null, out var plugin) - || plugin?.Instance is not IHasPluginConfiguration configPlugin) + var plugin = _pluginManager.GetPlugin(pluginId); + if (plugin?.Instance is not IHasPluginConfiguration configPlugin) { return NotFound(); } @@ -289,14 +292,15 @@ namespace Jellyfin.Api.Controllers [AllowAnonymous] public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - var imgPath = Path.Combine(plugin!.Path, plugin!.Manifest.ImageUrl ?? string.Empty); + var imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl ?? string.Empty); if (((ServerConfiguration)_config.CommonConfiguration).DisablePluginImages - || plugin!.Manifest.ImageUrl == null + || plugin.Manifest.ImageUrl == null || !System.IO.File.Exists(imgPath)) { // Use a blank image. @@ -325,9 +329,11 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult<PluginManifest> GetPluginManifest([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId); + + if (plugin != null) { - return Ok(plugin!.Manifest); + return Ok(plugin.Manifest); } return NotFound(); diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs index 071b51969..7f7381b03 100644 --- a/MediaBrowser.Common/Plugins/IPluginManager.cs +++ b/MediaBrowser.Common/Plugins/IPluginManager.cs @@ -72,9 +72,8 @@ namespace MediaBrowser.Common.Plugins /// </summary> /// <param name="id">Id of plugin.</param> /// <param name="version">The version of the plugin to locate.</param> - /// <param name="plugin">A <see cref="LocalPlugin"/> if found, otherwise null.</param> - /// <returns>Boolean value signifying the success of the search.</returns> - bool TryGetPlugin(Guid id, Version? version, out LocalPlugin? plugin); + /// <returns>A <see cref="LocalPlugin"/> if located, or null if not.</returns> + LocalPlugin? GetPlugin(Guid id, Version? version = null); /// <summary> /// Removes the plugin. |
