InstallationManager.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using MediaBrowser.Common;
  9. using MediaBrowser.Common.Configuration;
  10. using MediaBrowser.Common.Net;
  11. using MediaBrowser.Common.Plugins;
  12. using MediaBrowser.Common.Progress;
  13. using MediaBrowser.Common.Updates;
  14. using MediaBrowser.Controller.Configuration;
  15. using MediaBrowser.Model.Cryptography;
  16. using MediaBrowser.Model.Events;
  17. using MediaBrowser.Model.IO;
  18. using MediaBrowser.Model.Serialization;
  19. using MediaBrowser.Model.Updates;
  20. using Microsoft.Extensions.Logging;
  21. namespace Emby.Server.Implementations.Updates
  22. {
  23. /// <summary>
  24. /// Manages all install, uninstall and update operations (both plugins and system)
  25. /// </summary>
  26. public class InstallationManager : IInstallationManager
  27. {
  28. public event EventHandler<InstallationEventArgs> PackageInstalling;
  29. public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
  30. public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
  31. public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
  32. /// <summary>
  33. /// The current installations
  34. /// </summary>
  35. public List<Tuple<InstallationInfo, CancellationTokenSource>> CurrentInstallations { get; set; }
  36. /// <summary>
  37. /// The completed installations
  38. /// </summary>
  39. private ConcurrentBag<InstallationInfo> CompletedInstallationsInternal { get; set; }
  40. public IEnumerable<InstallationInfo> CompletedInstallations => CompletedInstallationsInternal;
  41. #region PluginUninstalled Event
  42. /// <summary>
  43. /// Occurs when [plugin uninstalled].
  44. /// </summary>
  45. public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
  46. /// <summary>
  47. /// Called when [plugin uninstalled].
  48. /// </summary>
  49. /// <param name="plugin">The plugin.</param>
  50. private void OnPluginUninstalled(IPlugin plugin)
  51. {
  52. PluginUninstalled?.Invoke(this, new GenericEventArgs<IPlugin> { Argument = plugin });
  53. }
  54. #endregion
  55. #region PluginUpdated Event
  56. /// <summary>
  57. /// Occurs when [plugin updated].
  58. /// </summary>
  59. public event EventHandler<GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>>> PluginUpdated;
  60. /// <summary>
  61. /// Called when [plugin updated].
  62. /// </summary>
  63. /// <param name="plugin">The plugin.</param>
  64. /// <param name="newVersion">The new version.</param>
  65. private void OnPluginUpdated(IPlugin plugin, PackageVersionInfo newVersion)
  66. {
  67. _logger.LogInformation("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.versionStr ?? string.Empty, newVersion.classification);
  68. PluginUpdated?.Invoke(this, new GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> { Argument = new Tuple<IPlugin, PackageVersionInfo>(plugin, newVersion) });
  69. _applicationHost.NotifyPendingRestart();
  70. }
  71. #endregion
  72. #region PluginInstalled Event
  73. /// <summary>
  74. /// Occurs when [plugin updated].
  75. /// </summary>
  76. public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
  77. /// <summary>
  78. /// Called when [plugin installed].
  79. /// </summary>
  80. /// <param name="package">The package.</param>
  81. private void OnPluginInstalled(PackageVersionInfo package)
  82. {
  83. _logger.LogInformation("New plugin installed: {0} {1} {2}", package.name, package.versionStr ?? string.Empty, package.classification);
  84. PluginInstalled?.Invoke(this, new GenericEventArgs<PackageVersionInfo> { Argument = package });
  85. _applicationHost.NotifyPendingRestart();
  86. }
  87. #endregion
  88. /// <summary>
  89. /// The _logger
  90. /// </summary>
  91. private readonly ILogger _logger;
  92. private readonly IApplicationPaths _appPaths;
  93. private readonly IHttpClient _httpClient;
  94. private readonly IJsonSerializer _jsonSerializer;
  95. private readonly IServerConfigurationManager _config;
  96. private readonly IFileSystem _fileSystem;
  97. /// <summary>
  98. /// Gets the application host.
  99. /// </summary>
  100. /// <value>The application host.</value>
  101. private readonly IApplicationHost _applicationHost;
  102. private readonly ICryptoProvider _cryptographyProvider;
  103. // netframework or netcore
  104. private readonly string _packageRuntime;
  105. public InstallationManager(
  106. ILoggerFactory loggerFactory,
  107. IApplicationHost appHost,
  108. IApplicationPaths appPaths,
  109. IHttpClient httpClient,
  110. IJsonSerializer jsonSerializer,
  111. IServerConfigurationManager config,
  112. IFileSystem fileSystem,
  113. ICryptoProvider cryptographyProvider,
  114. string packageRuntime)
  115. {
  116. if (loggerFactory == null)
  117. {
  118. throw new ArgumentNullException(nameof(loggerFactory));
  119. }
  120. CurrentInstallations = new List<Tuple<InstallationInfo, CancellationTokenSource>>();
  121. CompletedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
  122. _applicationHost = appHost;
  123. _appPaths = appPaths;
  124. _httpClient = httpClient;
  125. _jsonSerializer = jsonSerializer;
  126. _config = config;
  127. _fileSystem = fileSystem;
  128. _cryptographyProvider = cryptographyProvider;
  129. _packageRuntime = packageRuntime;
  130. _logger = loggerFactory.CreateLogger(nameof(InstallationManager));
  131. }
  132. private static Version GetPackageVersion(PackageVersionInfo version)
  133. {
  134. return new Version(ValueOrDefault(version.versionStr, "0.0.0.1"));
  135. }
  136. private static string ValueOrDefault(string str, string def)
  137. {
  138. return string.IsNullOrEmpty(str) ? def : str;
  139. }
  140. /// <summary>
  141. /// Gets all available packages.
  142. /// </summary>
  143. /// <returns>Task{List{PackageInfo}}.</returns>
  144. public async Task<List<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken,
  145. bool withRegistration = true,
  146. string packageType = null,
  147. Version applicationVersion = null)
  148. {
  149. // TODO cvium: when plugins get back this would need to be fixed
  150. // var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  151. return new List<PackageInfo>(); //FilterPackages(packages, packageType, applicationVersion);
  152. }
  153. /// <summary>
  154. /// Gets all available packages.
  155. /// </summary>
  156. /// <param name="cancellationToken">The cancellation token.</param>
  157. /// <returns>Task{List{PackageInfo}}.</returns>
  158. public async Task<List<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
  159. {
  160. using (var response = await _httpClient.SendAsync(new HttpRequestOptions
  161. {
  162. Url = "https://www.mb3admin.local/admin/service/EmbyPackages.json",
  163. CancellationToken = cancellationToken,
  164. Progress = new SimpleProgress<double>(),
  165. CacheLength = GetCacheLength(),
  166. CacheMode = CacheMode.Unconditional
  167. }, "GET").ConfigureAwait(false))
  168. {
  169. using (var stream = response.Content)
  170. {
  171. return FilterPackages(await _jsonSerializer.DeserializeFromStreamAsync<PackageInfo[]>(stream).ConfigureAwait(false));
  172. }
  173. }
  174. }
  175. private PackageVersionClass GetSystemUpdateLevel()
  176. {
  177. return _applicationHost.SystemUpdateLevel;
  178. }
  179. private static TimeSpan GetCacheLength()
  180. {
  181. return TimeSpan.FromMinutes(3);
  182. }
  183. protected List<PackageInfo> FilterPackages(IEnumerable<PackageInfo> packages)
  184. {
  185. var list = new List<PackageInfo>();
  186. foreach (var package in packages)
  187. {
  188. var versions = new List<PackageVersionInfo>();
  189. foreach (var version in package.versions)
  190. {
  191. if (string.IsNullOrEmpty(version.sourceUrl))
  192. {
  193. continue;
  194. }
  195. if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
  196. {
  197. continue;
  198. }
  199. versions.Add(version);
  200. }
  201. package.versions = versions
  202. .OrderByDescending(GetPackageVersion)
  203. .ToArray();
  204. if (package.versions.Length == 0)
  205. {
  206. continue;
  207. }
  208. list.Add(package);
  209. }
  210. // Remove packages with no versions
  211. return list;
  212. }
  213. protected List<PackageInfo> FilterPackages(IEnumerable<PackageInfo> packages, string packageType, Version applicationVersion)
  214. {
  215. var packagesList = FilterPackages(packages);
  216. var returnList = new List<PackageInfo>();
  217. var filterOnPackageType = !string.IsNullOrEmpty(packageType);
  218. foreach (var p in packagesList)
  219. {
  220. if (filterOnPackageType && !string.Equals(p.type, packageType, StringComparison.OrdinalIgnoreCase))
  221. {
  222. continue;
  223. }
  224. // If an app version was supplied, filter the versions for each package to only include supported versions
  225. if (applicationVersion != null)
  226. {
  227. p.versions = p.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToArray();
  228. }
  229. if (p.versions.Length == 0)
  230. {
  231. continue;
  232. }
  233. returnList.Add(p);
  234. }
  235. return returnList;
  236. }
  237. /// <summary>
  238. /// Determines whether [is package version up to date] [the specified package version info].
  239. /// </summary>
  240. /// <param name="packageVersionInfo">The package version info.</param>
  241. /// <param name="currentServerVersion">The current server version.</param>
  242. /// <returns><c>true</c> if [is package version up to date] [the specified package version info]; otherwise, <c>false</c>.</returns>
  243. private static bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version currentServerVersion)
  244. {
  245. if (string.IsNullOrEmpty(packageVersionInfo.requiredVersionStr))
  246. {
  247. return true;
  248. }
  249. return Version.TryParse(packageVersionInfo.requiredVersionStr, out var requiredVersion) && currentServerVersion >= requiredVersion;
  250. }
  251. /// <summary>
  252. /// Gets the package.
  253. /// </summary>
  254. /// <param name="name">The name.</param>
  255. /// <param name="guid">The assembly guid</param>
  256. /// <param name="classification">The classification.</param>
  257. /// <param name="version">The version.</param>
  258. /// <returns>Task{PackageVersionInfo}.</returns>
  259. public async Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version)
  260. {
  261. var packages = await GetAvailablePackages(CancellationToken.None, false).ConfigureAwait(false);
  262. var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  263. ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  264. if (package == null)
  265. {
  266. return null;
  267. }
  268. return package.versions.FirstOrDefault(v => GetPackageVersion(v).Equals(version) && v.classification == classification);
  269. }
  270. /// <summary>
  271. /// Gets the latest compatible version.
  272. /// </summary>
  273. /// <param name="name">The name.</param>
  274. /// <param name="guid">The assembly guid if this is a plug-in</param>
  275. /// <param name="currentServerVersion">The current server version.</param>
  276. /// <param name="classification">The classification.</param>
  277. /// <returns>Task{PackageVersionInfo}.</returns>
  278. public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  279. {
  280. var packages = await GetAvailablePackages(CancellationToken.None, false).ConfigureAwait(false);
  281. return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification);
  282. }
  283. /// <summary>
  284. /// Gets the latest compatible version.
  285. /// </summary>
  286. /// <param name="availablePackages">The available packages.</param>
  287. /// <param name="name">The name.</param>
  288. /// <param name="currentServerVersion">The current server version.</param>
  289. /// <param name="classification">The classification.</param>
  290. /// <returns>PackageVersionInfo.</returns>
  291. public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  292. {
  293. var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  294. ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  295. if (package == null)
  296. {
  297. return null;
  298. }
  299. return package.versions
  300. .OrderByDescending(GetPackageVersion)
  301. .FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion));
  302. }
  303. /// <summary>
  304. /// Gets the available plugin updates.
  305. /// </summary>
  306. /// <param name="applicationVersion">The current server version.</param>
  307. /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
  308. /// <param name="cancellationToken">The cancellation token.</param>
  309. /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
  310. public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version applicationVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken)
  311. {
  312. var catalog = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  313. var systemUpdateLevel = GetSystemUpdateLevel();
  314. // Figure out what needs to be installed
  315. return _applicationHost.Plugins.Select(p =>
  316. {
  317. var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, systemUpdateLevel);
  318. return latestPluginInfo != null && GetPackageVersion(latestPluginInfo) > p.Version ? latestPluginInfo : null;
  319. }).Where(i => i != null)
  320. .Where(p => !string.IsNullOrEmpty(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
  321. }
  322. /// <summary>
  323. /// Installs the package.
  324. /// </summary>
  325. /// <param name="package">The package.</param>
  326. /// <param name="isPlugin">if set to <c>true</c> [is plugin].</param>
  327. /// <param name="progress">The progress.</param>
  328. /// <param name="cancellationToken">The cancellation token.</param>
  329. /// <returns>Task.</returns>
  330. /// <exception cref="ArgumentNullException">package</exception>
  331. public async Task InstallPackage(PackageVersionInfo package, bool isPlugin, IProgress<double> progress, CancellationToken cancellationToken)
  332. {
  333. if (package == null)
  334. {
  335. throw new ArgumentNullException(nameof(package));
  336. }
  337. if (progress == null)
  338. {
  339. throw new ArgumentNullException(nameof(progress));
  340. }
  341. var installationInfo = new InstallationInfo
  342. {
  343. Id = Guid.NewGuid(),
  344. Name = package.name,
  345. AssemblyGuid = package.guid,
  346. UpdateClass = package.classification,
  347. Version = package.versionStr
  348. };
  349. var innerCancellationTokenSource = new CancellationTokenSource();
  350. var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
  351. // Add it to the in-progress list
  352. lock (CurrentInstallations)
  353. {
  354. CurrentInstallations.Add(tuple);
  355. }
  356. var innerProgress = new ActionableProgress<double>();
  357. // Whenever the progress updates, update the outer progress object and InstallationInfo
  358. innerProgress.RegisterAction(percent =>
  359. {
  360. progress.Report(percent);
  361. installationInfo.PercentComplete = percent;
  362. });
  363. var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
  364. var installationEventArgs = new InstallationEventArgs
  365. {
  366. InstallationInfo = installationInfo,
  367. PackageVersionInfo = package
  368. };
  369. PackageInstalling?.Invoke(this, installationEventArgs);
  370. try
  371. {
  372. await InstallPackageInternal(package, isPlugin, innerProgress, linkedToken).ConfigureAwait(false);
  373. lock (CurrentInstallations)
  374. {
  375. CurrentInstallations.Remove(tuple);
  376. }
  377. CompletedInstallationsInternal.Add(installationInfo);
  378. PackageInstallationCompleted?.Invoke(this, installationEventArgs);
  379. }
  380. catch (OperationCanceledException)
  381. {
  382. lock (CurrentInstallations)
  383. {
  384. CurrentInstallations.Remove(tuple);
  385. }
  386. _logger.LogInformation("Package installation cancelled: {0} {1}", package.name, package.versionStr);
  387. PackageInstallationCancelled?.Invoke(this, installationEventArgs);
  388. throw;
  389. }
  390. catch (Exception ex)
  391. {
  392. _logger.LogError(ex, "Package installation failed");
  393. lock (CurrentInstallations)
  394. {
  395. CurrentInstallations.Remove(tuple);
  396. }
  397. PackageInstallationFailed?.Invoke(this, new InstallationFailedEventArgs
  398. {
  399. InstallationInfo = installationInfo,
  400. Exception = ex
  401. });
  402. throw;
  403. }
  404. finally
  405. {
  406. // Dispose the progress object and remove the installation from the in-progress list
  407. tuple.Item2.Dispose();
  408. }
  409. }
  410. /// <summary>
  411. /// Installs the package internal.
  412. /// </summary>
  413. /// <param name="package">The package.</param>
  414. /// <param name="isPlugin">if set to <c>true</c> [is plugin].</param>
  415. /// <param name="progress">The progress.</param>
  416. /// <param name="cancellationToken">The cancellation token.</param>
  417. /// <returns>Task.</returns>
  418. private async Task InstallPackageInternal(PackageVersionInfo package, bool isPlugin, IProgress<double> progress, CancellationToken cancellationToken)
  419. {
  420. IPlugin plugin = null;
  421. if (isPlugin)
  422. {
  423. // Set last update time if we were installed before
  424. plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
  425. ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
  426. }
  427. string targetPath = plugin == null ? null : plugin.AssemblyFilePath;
  428. // Do the install
  429. await PerformPackageInstallation(progress, targetPath, package, cancellationToken).ConfigureAwait(false);
  430. // Do plugin-specific processing
  431. if (isPlugin)
  432. {
  433. if (plugin == null)
  434. {
  435. OnPluginInstalled(package);
  436. }
  437. else
  438. {
  439. OnPluginUpdated(plugin, package);
  440. }
  441. }
  442. }
  443. private async Task PerformPackageInstallation(IProgress<double> progress, string target, PackageVersionInfo package, CancellationToken cancellationToken)
  444. {
  445. // Target based on if it is an archive or single assembly
  446. // zip archives are assumed to contain directory structures relative to our ProgramDataPath
  447. var extension = Path.GetExtension(package.targetFilename);
  448. var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
  449. if (target == null)
  450. {
  451. target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
  452. }
  453. // Download to temporary file so that, if interrupted, it won't destroy the existing installation
  454. var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
  455. {
  456. Url = package.sourceUrl,
  457. CancellationToken = cancellationToken,
  458. Progress = progress
  459. }).ConfigureAwait(false);
  460. cancellationToken.ThrowIfCancellationRequested();
  461. // Validate with a checksum
  462. var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
  463. if (!packageChecksum.Equals(Guid.Empty)) // support for legacy uploads for now
  464. {
  465. using (var stream = File.OpenRead(tempFile))
  466. {
  467. var check = Guid.Parse(BitConverter.ToString(_cryptographyProvider.ComputeMD5(stream)).Replace("-", string.Empty));
  468. if (check != packageChecksum)
  469. {
  470. throw new Exception(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
  471. }
  472. }
  473. }
  474. cancellationToken.ThrowIfCancellationRequested();
  475. // Success - move it to the real target
  476. try
  477. {
  478. Directory.CreateDirectory(Path.GetDirectoryName(target));
  479. File.Copy(tempFile, target, true);
  480. //If it is an archive - write out a version file so we know what it is
  481. if (isArchive)
  482. {
  483. File.WriteAllText(target + ".ver", package.versionStr);
  484. }
  485. }
  486. catch (IOException ex)
  487. {
  488. _logger.LogError(ex, "Error attempting to move file from {TempFile} to {TargetFile}", tempFile, target);
  489. throw;
  490. }
  491. try
  492. {
  493. _fileSystem.DeleteFile(tempFile);
  494. }
  495. catch (IOException ex)
  496. {
  497. // Don't fail because of this
  498. _logger.LogError(ex, "Error deleting temp file {TempFile}", tempFile);
  499. }
  500. }
  501. /// <summary>
  502. /// Uninstalls a plugin
  503. /// </summary>
  504. /// <param name="plugin">The plugin.</param>
  505. /// <exception cref="ArgumentException"></exception>
  506. public void UninstallPlugin(IPlugin plugin)
  507. {
  508. plugin.OnUninstalling();
  509. // Remove it the quick way for now
  510. _applicationHost.RemovePlugin(plugin);
  511. var path = plugin.AssemblyFilePath;
  512. _logger.LogInformation("Deleting plugin file {0}", path);
  513. // Make this case-insensitive to account for possible incorrect assembly naming
  514. var file = _fileSystem.GetFilePaths(Path.GetDirectoryName(path))
  515. .FirstOrDefault(i => string.Equals(i, path, StringComparison.OrdinalIgnoreCase));
  516. if (!string.IsNullOrWhiteSpace(file))
  517. {
  518. path = file;
  519. }
  520. _fileSystem.DeleteFile(path);
  521. var list = _config.Configuration.UninstalledPlugins.ToList();
  522. var filename = Path.GetFileName(path);
  523. if (!list.Contains(filename, StringComparer.OrdinalIgnoreCase))
  524. {
  525. list.Add(filename);
  526. _config.Configuration.UninstalledPlugins = list.ToArray();
  527. _config.SaveConfiguration();
  528. }
  529. OnPluginUninstalled(plugin);
  530. _applicationHost.NotifyPendingRestart();
  531. }
  532. /// <summary>
  533. /// Releases unmanaged and - optionally - managed resources.
  534. /// </summary>
  535. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  536. protected virtual void Dispose(bool dispose)
  537. {
  538. if (dispose)
  539. {
  540. lock (CurrentInstallations)
  541. {
  542. foreach (var tuple in CurrentInstallations)
  543. {
  544. tuple.Item2.Dispose();
  545. }
  546. CurrentInstallations.Clear();
  547. }
  548. }
  549. }
  550. public void Dispose()
  551. {
  552. Dispose(true);
  553. }
  554. }
  555. }