InstallationManager.cs 25 KB

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