PluginManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #nullable enable
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Text.Json;
  9. using MediaBrowser.Common;
  10. using MediaBrowser.Common.Extensions;
  11. using MediaBrowser.Common.Json;
  12. using MediaBrowser.Common.Plugins;
  13. using MediaBrowser.Model.Configuration;
  14. using MediaBrowser.Model.Plugins;
  15. using Microsoft.Extensions.DependencyInjection;
  16. using Microsoft.Extensions.Logging;
  17. namespace Emby.Server.Implementations.Plugins
  18. {
  19. /// <summary>
  20. /// Defines the <see cref="PluginManager" />.
  21. /// </summary>
  22. public class PluginManager : IPluginManager
  23. {
  24. private readonly string _pluginsPath;
  25. private readonly Version _appVersion;
  26. private readonly JsonSerializerOptions _jsonOptions;
  27. private readonly ILogger<PluginManager> _logger;
  28. private readonly IApplicationHost _appHost;
  29. private readonly ServerConfiguration _config;
  30. private readonly IList<LocalPlugin> _plugins;
  31. private readonly Version _nextVersion;
  32. private readonly Version _minimumVersion;
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="PluginManager"/> class.
  35. /// </summary>
  36. /// <param name="logger">The <see cref="ILogger"/>.</param>
  37. /// <param name="appHost">The <see cref="IApplicationHost"/>.</param>
  38. /// <param name="config">The <see cref="ServerConfiguration"/>.</param>
  39. /// <param name="pluginsPath">The plugin path.</param>
  40. /// <param name="appVersion">The application version.</param>
  41. public PluginManager(
  42. ILogger<PluginManager> logger,
  43. IApplicationHost appHost,
  44. ServerConfiguration config,
  45. string pluginsPath,
  46. Version appVersion)
  47. {
  48. _logger = logger ?? throw new ArgumentNullException(nameof(logger));
  49. _pluginsPath = pluginsPath;
  50. _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion));
  51. _jsonOptions = JsonDefaults.GetOptions();
  52. _config = config;
  53. _appHost = appHost;
  54. _nextVersion = new Version(_appVersion.Major, _appVersion.Minor + 2, _appVersion.Build, _appVersion.Revision);
  55. _minimumVersion = new Version(0, 0, 0, 1);
  56. _plugins = Directory.Exists(_pluginsPath) ? DiscoverPlugins().ToList() : new List<LocalPlugin>();
  57. }
  58. /// <summary>
  59. /// Gets the Plugins.
  60. /// </summary>
  61. public IList<LocalPlugin> Plugins => _plugins;
  62. /// <summary>
  63. /// Returns all the assemblies.
  64. /// </summary>
  65. /// <returns>An IEnumerable{Assembly}.</returns>
  66. public IEnumerable<Assembly> LoadAssemblies()
  67. {
  68. // Attempt to remove any deleted plugins and change any successors to be active.
  69. for (int a = _plugins.Count - 1; a >= 0; a--)
  70. {
  71. var plugin = _plugins[a];
  72. if (plugin.Manifest.Status == PluginStatus.Deleted && DeletePlugin(plugin))
  73. {
  74. UpdateSuccessors(plugin);
  75. }
  76. }
  77. // Now load the assemblies..
  78. foreach (var plugin in _plugins)
  79. {
  80. CheckIfStillSuperceded(plugin);
  81. if (plugin.IsEnabledAndSupported == false)
  82. {
  83. _logger.LogInformation("Skipping disabled plugin {Version} of {Name} ", plugin.Version, plugin.Name);
  84. continue;
  85. }
  86. foreach (var file in plugin.DllFiles)
  87. {
  88. Assembly assembly;
  89. try
  90. {
  91. assembly = Assembly.LoadFrom(file);
  92. }
  93. catch (FileLoadException ex)
  94. {
  95. _logger.LogError(ex, "Failed to load assembly {Path}. Disabling plugin.", file);
  96. ChangePluginState(plugin, PluginStatus.Malfunctioned);
  97. continue;
  98. }
  99. _logger.LogInformation("Loaded assembly {Assembly} from {Path}", assembly.FullName, file);
  100. yield return assembly;
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// Creates all the plugin instances.
  106. /// </summary>
  107. public void CreatePlugins()
  108. {
  109. var createdPlugins = _appHost.GetExports<IPlugin>(CreatePluginInstance)
  110. .Where(i => i != null)
  111. .ToArray();
  112. }
  113. /// <summary>
  114. /// Registers the plugin's services with the DI.
  115. /// Note: DI is not yet instantiated yet.
  116. /// </summary>
  117. /// <param name="serviceCollection">A <see cref="ServiceCollection"/> instance.</param>
  118. public void RegisterServices(IServiceCollection serviceCollection)
  119. {
  120. foreach (var pluginServiceRegistrator in _appHost.GetExportTypes<IPluginServiceRegistrator>())
  121. {
  122. var plugin = GetPluginByType(pluginServiceRegistrator.Assembly.GetType());
  123. if (plugin == null)
  124. {
  125. _logger.LogError("Unable to find plugin in assembly {Assembly}", pluginServiceRegistrator.Assembly.FullName);
  126. continue;
  127. }
  128. CheckIfStillSuperceded(plugin);
  129. if (!plugin.IsEnabledAndSupported)
  130. {
  131. continue;
  132. }
  133. try
  134. {
  135. var instance = (IPluginServiceRegistrator?)Activator.CreateInstance(pluginServiceRegistrator);
  136. instance?.RegisterServices(serviceCollection);
  137. }
  138. #pragma warning disable CA1031 // Do not catch general exception types
  139. catch (Exception ex)
  140. #pragma warning restore CA1031 // Do not catch general exception types
  141. {
  142. _logger.LogError(ex, "Error registering plugin services from {Assembly}.", pluginServiceRegistrator.Assembly.FullName);
  143. if (ChangePluginState(plugin, PluginStatus.Malfunctioned))
  144. {
  145. _logger.LogInformation("Disabling plugin {Path}", plugin.Path);
  146. }
  147. }
  148. }
  149. }
  150. /// <summary>
  151. /// Imports a plugin manifest from <paramref name="folder"/>.
  152. /// </summary>
  153. /// <param name="folder">Folder of the plugin.</param>
  154. public void ImportPluginFrom(string folder)
  155. {
  156. if (string.IsNullOrEmpty(folder))
  157. {
  158. throw new ArgumentNullException(nameof(folder));
  159. }
  160. // Load the plugin.
  161. var plugin = LoadManifest(folder);
  162. // Make sure we haven't already loaded this.
  163. if (plugin == null || _plugins.Any(p => p.Manifest.Equals(plugin.Manifest)))
  164. {
  165. return;
  166. }
  167. _plugins.Add(plugin);
  168. EnablePlugin(plugin);
  169. }
  170. /// <summary>
  171. /// Removes the plugin reference '<paramref name="plugin"/>.
  172. /// </summary>
  173. /// <param name="plugin">The plugin.</param>
  174. /// <returns>Outcome of the operation.</returns>
  175. public bool RemovePlugin(LocalPlugin plugin)
  176. {
  177. if (plugin == null)
  178. {
  179. throw new ArgumentNullException(nameof(plugin));
  180. }
  181. if (DeletePlugin(plugin))
  182. {
  183. return true;
  184. }
  185. _logger.LogWarning("Unable to delete {Path}, so marking as deleteOnStartup.", plugin.Path);
  186. // Unable to delete, so disable.
  187. return ChangePluginState(plugin, PluginStatus.Deleted);
  188. }
  189. /// <summary>
  190. /// Attempts to find the plugin with and id of <paramref name="id"/>.
  191. /// </summary>
  192. /// <param name="id">The <see cref="Guid"/> of plugin.</param>
  193. /// <param name="version">Optional <see cref="Version"/> of the plugin to locate.</param>
  194. /// <returns>A <see cref="LocalPlugin"/> if located, or null if not.</returns>
  195. public LocalPlugin? GetPlugin(Guid id, Version? version = null)
  196. {
  197. LocalPlugin? plugin;
  198. if (version == null)
  199. {
  200. // If no version is given, return the current instance.
  201. var plugins = _plugins.Where(p => p.Id.Equals(id));
  202. plugin = plugins.FirstOrDefault(p => p.Instance != null);
  203. if (plugin == null)
  204. {
  205. plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault();
  206. }
  207. }
  208. else
  209. {
  210. // Match id and version number.
  211. plugin = _plugins.FirstOrDefault(p => p.Id.Equals(id) && p.Version.Equals(version));
  212. }
  213. return plugin;
  214. }
  215. /// <summary>
  216. /// Enables the plugin, disabling all other versions.
  217. /// </summary>
  218. /// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
  219. public void EnablePlugin(LocalPlugin plugin)
  220. {
  221. if (plugin == null)
  222. {
  223. throw new ArgumentNullException(nameof(plugin));
  224. }
  225. if (ChangePluginState(plugin, PluginStatus.Active))
  226. {
  227. UpdateSuccessors(plugin);
  228. }
  229. }
  230. /// <summary>
  231. /// Disable the plugin.
  232. /// </summary>
  233. /// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
  234. public void DisablePlugin(LocalPlugin plugin)
  235. {
  236. if (plugin == null)
  237. {
  238. throw new ArgumentNullException(nameof(plugin));
  239. }
  240. // Update the manifest on disk
  241. if (ChangePluginState(plugin, PluginStatus.Disabled))
  242. {
  243. UpdateSuccessors(plugin);
  244. }
  245. }
  246. /// <summary>
  247. /// Disable the plugin.
  248. /// </summary>
  249. /// <param name="assembly">The <see cref="Assembly"/> of the plug to disable.</param>
  250. public void FailPlugin(Assembly assembly)
  251. {
  252. // Only save if disabled.
  253. if (assembly == null)
  254. {
  255. throw new ArgumentNullException(nameof(assembly));
  256. }
  257. var plugin = _plugins.Where(p => p.DllFiles.Contains(assembly.Location)).FirstOrDefault();
  258. if (plugin == null)
  259. {
  260. // A plugin's assembly didn't cause this issue, so ignore it.
  261. return;
  262. }
  263. ChangePluginState(plugin, PluginStatus.Malfunctioned);
  264. }
  265. /// <summary>
  266. /// Saves the manifest back to disk.
  267. /// </summary>
  268. /// <param name="manifest">The <see cref="PluginManifest"/> to save.</param>
  269. /// <param name="path">The path where to save the manifest.</param>
  270. /// <returns>True if successful.</returns>
  271. public bool SaveManifest(PluginManifest manifest, string path)
  272. {
  273. if (manifest == null)
  274. {
  275. return false;
  276. }
  277. try
  278. {
  279. var data = JsonSerializer.Serialize(manifest, _jsonOptions);
  280. File.WriteAllText(Path.Combine(path, "meta.json"), data, Encoding.UTF8);
  281. return true;
  282. }
  283. #pragma warning disable CA1031 // Do not catch general exception types
  284. catch (Exception e)
  285. #pragma warning restore CA1031 // Do not catch general exception types
  286. {
  287. _logger.LogWarning(e, "Unable to save plugin manifest. {Path}", path);
  288. return false;
  289. }
  290. }
  291. /// <summary>
  292. /// Changes a plugin's load status.
  293. /// </summary>
  294. /// <param name="plugin">The <see cref="LocalPlugin"/> instance.</param>
  295. /// <param name="state">The <see cref="PluginStatus"/> of the plugin.</param>
  296. /// <returns>Success of the task.</returns>
  297. private bool ChangePluginState(LocalPlugin plugin, PluginStatus state)
  298. {
  299. if (plugin.Manifest.Status == state || string.IsNullOrEmpty(plugin.Path))
  300. {
  301. // No need to save as the state hasn't changed.
  302. return true;
  303. }
  304. plugin.Manifest.Status = state;
  305. return SaveManifest(plugin.Manifest, plugin.Path);
  306. }
  307. /// <summary>
  308. /// Finds the plugin record using the type.
  309. /// </summary>
  310. /// <param name="type">The <see cref="Type"/> being sought.</param>
  311. /// <returns>The matching record, or null if not found.</returns>
  312. private LocalPlugin? GetPluginByType(Type type)
  313. {
  314. // Find which plugin it is by the path.
  315. return _plugins.FirstOrDefault(p => string.Equals(p.Path, Path.GetDirectoryName(type.Assembly.Location), StringComparison.Ordinal));
  316. }
  317. /// <summary>
  318. /// Creates the instance safe.
  319. /// </summary>
  320. /// <param name="type">The type.</param>
  321. /// <returns>System.Object.</returns>
  322. private IPlugin? CreatePluginInstance(Type type)
  323. {
  324. // Find the record for this plugin.
  325. var plugin = GetPluginByType(type);
  326. if (plugin?.Manifest.Status < PluginStatus.Active)
  327. {
  328. return null;
  329. }
  330. try
  331. {
  332. _logger.LogDebug("Creating instance of {Type}", type);
  333. var instance = (IPlugin)ActivatorUtilities.CreateInstance(_appHost.ServiceProvider, type);
  334. if (plugin == null)
  335. {
  336. // Create a dummy record for the providers.
  337. // TODO: remove this code, if all provided have been released as separate plugins.
  338. plugin = new LocalPlugin(
  339. instance.AssemblyFilePath,
  340. true,
  341. new PluginManifest
  342. {
  343. Id = instance.Id,
  344. Status = PluginStatus.Active,
  345. Name = instance.Name,
  346. Version = instance.Version.ToString()
  347. })
  348. {
  349. Instance = instance
  350. };
  351. _plugins.Add(plugin);
  352. plugin.Manifest.Status = PluginStatus.Active;
  353. }
  354. else
  355. {
  356. plugin.Instance = instance;
  357. var manifest = plugin.Manifest;
  358. var pluginStr = plugin.Instance.Version.ToString();
  359. bool changed = false;
  360. if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal))
  361. {
  362. // If a plugin without a manifest failed to load due to an external issue (eg config),
  363. // this updates the manifest to the actual plugin values.
  364. manifest.Version = pluginStr;
  365. manifest.Name = plugin.Instance.Name;
  366. manifest.Description = plugin.Instance.Description;
  367. changed = true;
  368. }
  369. changed = changed || manifest.Status != PluginStatus.Active;
  370. manifest.Status = PluginStatus.Active;
  371. if (changed)
  372. {
  373. SaveManifest(manifest, plugin.Path);
  374. }
  375. }
  376. _logger.LogInformation("Loaded plugin: {PluginName} {PluginVersion}", plugin.Name, plugin.Version);
  377. return instance;
  378. }
  379. #pragma warning disable CA1031 // Do not catch general exception types
  380. catch (Exception ex)
  381. #pragma warning restore CA1031 // Do not catch general exception types
  382. {
  383. _logger.LogError(ex, "Error creating {Type}", type.FullName);
  384. if (plugin != null)
  385. {
  386. if (ChangePluginState(plugin, PluginStatus.Malfunctioned))
  387. {
  388. _logger.LogInformation("Plugin {Path} has been disabled.", plugin.Path);
  389. return null;
  390. }
  391. }
  392. _logger.LogDebug("Unable to auto-disable.");
  393. return null;
  394. }
  395. }
  396. private void CheckIfStillSuperceded(LocalPlugin plugin)
  397. {
  398. if (plugin.Manifest.Status != PluginStatus.Superceded)
  399. {
  400. return;
  401. }
  402. var predecessor = _plugins.OrderByDescending(p => p.Version)
  403. .FirstOrDefault(p => p.Id.Equals(plugin.Id) && p.IsEnabledAndSupported && p.Version != plugin.Version);
  404. if (predecessor != null)
  405. {
  406. return;
  407. }
  408. plugin.Manifest.Status = PluginStatus.Active;
  409. }
  410. /// <summary>
  411. /// Attempts to delete a plugin.
  412. /// </summary>
  413. /// <param name="plugin">A <see cref="LocalPlugin"/> instance to delete.</param>
  414. /// <returns>True if successful.</returns>
  415. private bool DeletePlugin(LocalPlugin plugin)
  416. {
  417. // Attempt a cleanup of old folders.
  418. try
  419. {
  420. Directory.Delete(plugin.Path, true);
  421. _logger.LogDebug("Deleted {Path}", plugin.Path);
  422. _plugins.Remove(plugin);
  423. }
  424. #pragma warning disable CA1031 // Do not catch general exception types
  425. catch
  426. #pragma warning restore CA1031 // Do not catch general exception types
  427. {
  428. return false;
  429. }
  430. return _plugins.Remove(plugin);
  431. }
  432. private LocalPlugin? LoadManifest(string dir)
  433. {
  434. try
  435. {
  436. Version? version;
  437. PluginManifest? manifest = null;
  438. var metafile = Path.Combine(dir, "meta.json");
  439. if (File.Exists(metafile))
  440. {
  441. try
  442. {
  443. var data = File.ReadAllText(metafile, Encoding.UTF8);
  444. manifest = JsonSerializer.Deserialize<PluginManifest>(data, _jsonOptions);
  445. }
  446. #pragma warning disable CA1031 // Do not catch general exception types
  447. catch (Exception ex)
  448. #pragma warning restore CA1031 // Do not catch general exception types
  449. {
  450. _logger.LogError(ex, "Error deserializing {Path}.", dir);
  451. }
  452. }
  453. if (manifest != null)
  454. {
  455. if (!Version.TryParse(manifest.TargetAbi, out var targetAbi))
  456. {
  457. targetAbi = _minimumVersion;
  458. }
  459. if (!Version.TryParse(manifest.Version, out version))
  460. {
  461. manifest.Version = _minimumVersion.ToString();
  462. }
  463. return new LocalPlugin(dir, _appVersion >= targetAbi, manifest);
  464. }
  465. // No metafile, so lets see if the folder is versioned.
  466. // TODO: Phase this support out in future versions.
  467. metafile = dir.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)[^1];
  468. int versionIndex = dir.LastIndexOf('_');
  469. if (versionIndex != -1)
  470. {
  471. // Get the version number from the filename if possible.
  472. metafile = Path.GetFileName(dir[..versionIndex]) ?? dir[..versionIndex];
  473. version = Version.TryParse(dir.AsSpan()[(versionIndex + 1)..], out Version? parsedVersion) ? parsedVersion : _appVersion;
  474. }
  475. else
  476. {
  477. // Un-versioned folder - Add it under the path name and version it suitable for this instance.
  478. version = _appVersion;
  479. }
  480. // Auto-create a plugin manifest, so we can disable it, if it fails to load.
  481. manifest = new PluginManifest
  482. {
  483. Status = PluginStatus.Restart,
  484. Name = metafile,
  485. AutoUpdate = false,
  486. Id = metafile.GetMD5(),
  487. TargetAbi = _appVersion.ToString(),
  488. Version = version.ToString()
  489. };
  490. return new LocalPlugin(dir, true, manifest);
  491. }
  492. #pragma warning disable CA1031 // Do not catch general exception types
  493. catch (Exception ex)
  494. #pragma warning restore CA1031 // Do not catch general exception types
  495. {
  496. _logger.LogError(ex, "Something went wrong!");
  497. return null;
  498. }
  499. }
  500. /// <summary>
  501. /// Gets the list of local plugins.
  502. /// </summary>
  503. /// <returns>Enumerable of local plugins.</returns>
  504. private IEnumerable<LocalPlugin> DiscoverPlugins()
  505. {
  506. var versions = new List<LocalPlugin>();
  507. if (!Directory.Exists(_pluginsPath))
  508. {
  509. // Plugin path doesn't exist, don't try to enumerate sub-folders.
  510. return Enumerable.Empty<LocalPlugin>();
  511. }
  512. var directories = Directory.EnumerateDirectories(_pluginsPath, "*.*", SearchOption.TopDirectoryOnly);
  513. LocalPlugin? entry;
  514. foreach (var dir in directories)
  515. {
  516. entry = LoadManifest(dir);
  517. if (entry != null)
  518. {
  519. versions.Add(entry);
  520. }
  521. }
  522. string lastName = string.Empty;
  523. versions.Sort(LocalPlugin.Compare);
  524. // Traverse backwards through the list.
  525. // The first item will be the latest version.
  526. for (int x = versions.Count - 1; x >= 0; x--)
  527. {
  528. entry = versions[x];
  529. if (!string.Equals(lastName, entry.Name, StringComparison.OrdinalIgnoreCase))
  530. {
  531. entry.DllFiles.AddRange(Directory.EnumerateFiles(entry.Path, "*.dll", SearchOption.AllDirectories));
  532. if (entry.IsEnabledAndSupported)
  533. {
  534. lastName = entry.Name;
  535. continue;
  536. }
  537. }
  538. if (string.IsNullOrEmpty(lastName))
  539. {
  540. continue;
  541. }
  542. var manifest = entry.Manifest;
  543. var cleaned = false;
  544. var path = entry.Path;
  545. if (_config.RemoveOldPlugins)
  546. {
  547. // Attempt a cleanup of old folders.
  548. try
  549. {
  550. _logger.LogDebug("Deleting {Path}", path);
  551. Directory.Delete(path, true);
  552. cleaned = true;
  553. }
  554. #pragma warning disable CA1031 // Do not catch general exception types
  555. catch (Exception e)
  556. #pragma warning restore CA1031 // Do not catch general exception types
  557. {
  558. _logger.LogWarning(e, "Unable to delete {Path}", path);
  559. }
  560. if (cleaned)
  561. {
  562. versions.RemoveAt(x);
  563. }
  564. else
  565. {
  566. if (manifest == null)
  567. {
  568. _logger.LogWarning("Unable to disable plugin {Path}", entry.Path);
  569. continue;
  570. }
  571. if (manifest.Status != PluginStatus.Deleted)
  572. {
  573. manifest.Status = PluginStatus.Deleted;
  574. SaveManifest(manifest, entry.Path);
  575. }
  576. }
  577. }
  578. }
  579. // Only want plugin folders which have files.
  580. return versions.Where(p => p.DllFiles.Count != 0);
  581. }
  582. /// <summary>
  583. /// Changes the status of the other versions of the plugin to "Superceded".
  584. /// </summary>
  585. /// <param name="plugin">The <see cref="LocalPlugin"/> that's master.</param>
  586. private void UpdateSuccessors(LocalPlugin plugin)
  587. {
  588. // This value is memory only - so that the web will show restart required.
  589. plugin.Manifest.Status = PluginStatus.Restart;
  590. // Detect whether there is another version of this plugin that needs disabling.
  591. var predecessor = _plugins.OrderByDescending(p => p.Version)
  592. .FirstOrDefault(
  593. p => p.Id.Equals(plugin.Id)
  594. && p.IsEnabledAndSupported
  595. && p.Version != plugin.Version);
  596. if (predecessor == null)
  597. {
  598. return;
  599. }
  600. if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded))
  601. {
  602. _logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name);
  603. }
  604. }
  605. }
  606. }