InstallationManager.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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 Task<List<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken,
  145. bool withRegistration = true,
  146. string packageType = null,
  147. Version applicationVersion = null)
  148. {
  149. var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  150. return FilterPackages(packages, packageType, applicationVersion);
  151. }
  152. /// <summary>
  153. /// Gets all available packages.
  154. /// </summary>
  155. /// <param name="cancellationToken">The cancellation token.</param>
  156. /// <returns>Task{List{PackageInfo}}.</returns>
  157. public async Task<List<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
  158. {
  159. using (var response = await _httpClient.SendAsync(new HttpRequestOptions
  160. {
  161. Url = "https://repo.jellyfin.org/releases/plugin/manifest.json",
  162. CancellationToken = cancellationToken,
  163. Progress = new SimpleProgress<double>(),
  164. CacheLength = GetCacheLength()
  165. }, "GET").ConfigureAwait(false))
  166. {
  167. using (var stream = response.Content)
  168. {
  169. return FilterPackages(await _jsonSerializer.DeserializeFromStreamAsync<PackageInfo[]>(stream).ConfigureAwait(false));
  170. }
  171. }
  172. }
  173. private PackageVersionClass GetSystemUpdateLevel()
  174. {
  175. return _applicationHost.SystemUpdateLevel;
  176. }
  177. private static TimeSpan GetCacheLength()
  178. {
  179. return TimeSpan.FromMinutes(3);
  180. }
  181. protected List<PackageInfo> FilterPackages(IEnumerable<PackageInfo> packages)
  182. {
  183. var list = new List<PackageInfo>();
  184. foreach (var package in packages)
  185. {
  186. var versions = new List<PackageVersionInfo>();
  187. foreach (var version in package.versions)
  188. {
  189. if (string.IsNullOrEmpty(version.sourceUrl))
  190. {
  191. continue;
  192. }
  193. if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
  194. {
  195. continue;
  196. }
  197. versions.Add(version);
  198. }
  199. package.versions = versions
  200. .OrderByDescending(GetPackageVersion)
  201. .ToArray();
  202. if (package.versions.Length == 0)
  203. {
  204. continue;
  205. }
  206. list.Add(package);
  207. }
  208. // Remove packages with no versions
  209. return list;
  210. }
  211. protected List<PackageInfo> FilterPackages(IEnumerable<PackageInfo> packages, string packageType, Version applicationVersion)
  212. {
  213. var packagesList = FilterPackages(packages);
  214. var returnList = new List<PackageInfo>();
  215. var filterOnPackageType = !string.IsNullOrEmpty(packageType);
  216. foreach (var p in packagesList)
  217. {
  218. if (filterOnPackageType && !string.Equals(p.type, packageType, StringComparison.OrdinalIgnoreCase))
  219. {
  220. continue;
  221. }
  222. // If an app version was supplied, filter the versions for each package to only include supported versions
  223. if (applicationVersion != null)
  224. {
  225. p.versions = p.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToArray();
  226. }
  227. if (p.versions.Length == 0)
  228. {
  229. continue;
  230. }
  231. returnList.Add(p);
  232. }
  233. return returnList;
  234. }
  235. /// <summary>
  236. /// Determines whether [is package version up to date] [the specified package version info].
  237. /// </summary>
  238. /// <param name="packageVersionInfo">The package version info.</param>
  239. /// <param name="currentServerVersion">The current server version.</param>
  240. /// <returns><c>true</c> if [is package version up to date] [the specified package version info]; otherwise, <c>false</c>.</returns>
  241. private static bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version currentServerVersion)
  242. {
  243. if (string.IsNullOrEmpty(packageVersionInfo.requiredVersionStr))
  244. {
  245. return true;
  246. }
  247. return Version.TryParse(packageVersionInfo.requiredVersionStr, out var requiredVersion) && currentServerVersion >= requiredVersion;
  248. }
  249. /// <summary>
  250. /// Gets the package.
  251. /// </summary>
  252. /// <param name="name">The name.</param>
  253. /// <param name="guid">The assembly guid</param>
  254. /// <param name="classification">The classification.</param>
  255. /// <param name="version">The version.</param>
  256. /// <returns>Task{PackageVersionInfo}.</returns>
  257. public async Task<PackageVersionInfo> GetPackage(string name, string guid, PackageVersionClass classification, Version version)
  258. {
  259. var packages = await GetAvailablePackages(CancellationToken.None, false).ConfigureAwait(false);
  260. var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  261. ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  262. if (package == null)
  263. {
  264. return null;
  265. }
  266. return package.versions.FirstOrDefault(v => GetPackageVersion(v).Equals(version) && v.classification == classification);
  267. }
  268. /// <summary>
  269. /// Gets the latest compatible version.
  270. /// </summary>
  271. /// <param name="name">The name.</param>
  272. /// <param name="guid">The assembly guid if this is a plug-in</param>
  273. /// <param name="currentServerVersion">The current server version.</param>
  274. /// <param name="classification">The classification.</param>
  275. /// <returns>Task{PackageVersionInfo}.</returns>
  276. public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  277. {
  278. var packages = await GetAvailablePackages(CancellationToken.None, false).ConfigureAwait(false);
  279. return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification);
  280. }
  281. /// <summary>
  282. /// Gets the latest compatible version.
  283. /// </summary>
  284. /// <param name="availablePackages">The available packages.</param>
  285. /// <param name="name">The name.</param>
  286. /// <param name="currentServerVersion">The current server version.</param>
  287. /// <param name="classification">The classification.</param>
  288. /// <returns>PackageVersionInfo.</returns>
  289. public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
  290. {
  291. var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase))
  292. ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
  293. if (package == null)
  294. {
  295. return null;
  296. }
  297. return package.versions
  298. .OrderByDescending(GetPackageVersion)
  299. .FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion));
  300. }
  301. /// <summary>
  302. /// Gets the available plugin updates.
  303. /// </summary>
  304. /// <param name="applicationVersion">The current server version.</param>
  305. /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
  306. /// <param name="cancellationToken">The cancellation token.</param>
  307. /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
  308. public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version applicationVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken)
  309. {
  310. var catalog = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  311. var systemUpdateLevel = GetSystemUpdateLevel();
  312. // Figure out what needs to be installed
  313. return _applicationHost.Plugins.Select(p =>
  314. {
  315. var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, systemUpdateLevel);
  316. return latestPluginInfo != null && GetPackageVersion(latestPluginInfo) > p.Version ? latestPluginInfo : null;
  317. }).Where(i => i != null)
  318. .Where(p => !string.IsNullOrEmpty(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
  319. }
  320. /// <summary>
  321. /// Installs the package.
  322. /// </summary>
  323. /// <param name="package">The package.</param>
  324. /// <param name="isPlugin">if set to <c>true</c> [is plugin].</param>
  325. /// <param name="progress">The progress.</param>
  326. /// <param name="cancellationToken">The cancellation token.</param>
  327. /// <returns>Task.</returns>
  328. /// <exception cref="ArgumentNullException">package</exception>
  329. public async Task InstallPackage(PackageVersionInfo package, bool isPlugin, IProgress<double> progress, CancellationToken cancellationToken)
  330. {
  331. if (package == null)
  332. {
  333. throw new ArgumentNullException(nameof(package));
  334. }
  335. if (progress == null)
  336. {
  337. throw new ArgumentNullException(nameof(progress));
  338. }
  339. var installationInfo = new InstallationInfo
  340. {
  341. Id = Guid.NewGuid(),
  342. Name = package.name,
  343. AssemblyGuid = package.guid,
  344. UpdateClass = package.classification,
  345. Version = package.versionStr
  346. };
  347. var innerCancellationTokenSource = new CancellationTokenSource();
  348. var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
  349. // Add it to the in-progress list
  350. lock (CurrentInstallations)
  351. {
  352. CurrentInstallations.Add(tuple);
  353. }
  354. var innerProgress = new ActionableProgress<double>();
  355. // Whenever the progress updates, update the outer progress object and InstallationInfo
  356. innerProgress.RegisterAction(percent =>
  357. {
  358. progress.Report(percent);
  359. installationInfo.PercentComplete = percent;
  360. });
  361. var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
  362. var installationEventArgs = new InstallationEventArgs
  363. {
  364. InstallationInfo = installationInfo,
  365. PackageVersionInfo = package
  366. };
  367. PackageInstalling?.Invoke(this, installationEventArgs);
  368. try
  369. {
  370. await InstallPackageInternal(package, isPlugin, innerProgress, linkedToken).ConfigureAwait(false);
  371. lock (CurrentInstallations)
  372. {
  373. CurrentInstallations.Remove(tuple);
  374. }
  375. CompletedInstallationsInternal.Add(installationInfo);
  376. PackageInstallationCompleted?.Invoke(this, installationEventArgs);
  377. }
  378. catch (OperationCanceledException)
  379. {
  380. lock (CurrentInstallations)
  381. {
  382. CurrentInstallations.Remove(tuple);
  383. }
  384. _logger.LogInformation("Package installation cancelled: {0} {1}", package.name, package.versionStr);
  385. PackageInstallationCancelled?.Invoke(this, installationEventArgs);
  386. throw;
  387. }
  388. catch (Exception ex)
  389. {
  390. _logger.LogError(ex, "Package installation failed");
  391. lock (CurrentInstallations)
  392. {
  393. CurrentInstallations.Remove(tuple);
  394. }
  395. PackageInstallationFailed?.Invoke(this, new InstallationFailedEventArgs
  396. {
  397. InstallationInfo = installationInfo,
  398. Exception = ex
  399. });
  400. throw;
  401. }
  402. finally
  403. {
  404. // Dispose the progress object and remove the installation from the in-progress list
  405. tuple.Item2.Dispose();
  406. }
  407. }
  408. /// <summary>
  409. /// Installs the package internal.
  410. /// </summary>
  411. /// <param name="package">The package.</param>
  412. /// <param name="isPlugin">if set to <c>true</c> [is plugin].</param>
  413. /// <param name="progress">The progress.</param>
  414. /// <param name="cancellationToken">The cancellation token.</param>
  415. /// <returns>Task.</returns>
  416. private async Task InstallPackageInternal(PackageVersionInfo package, bool isPlugin, IProgress<double> progress, CancellationToken cancellationToken)
  417. {
  418. IPlugin plugin = null;
  419. if (isPlugin)
  420. {
  421. // Set last update time if we were installed before
  422. plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
  423. ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
  424. }
  425. string targetPath = plugin == null ? null : plugin.AssemblyFilePath;
  426. // Do the install
  427. await PerformPackageInstallation(progress, targetPath, package, cancellationToken).ConfigureAwait(false);
  428. // Do plugin-specific processing
  429. if (isPlugin)
  430. {
  431. if (plugin == null)
  432. {
  433. OnPluginInstalled(package);
  434. }
  435. else
  436. {
  437. OnPluginUpdated(plugin, package);
  438. }
  439. }
  440. }
  441. private async Task PerformPackageInstallation(IProgress<double> progress, string target, PackageVersionInfo package, CancellationToken cancellationToken)
  442. {
  443. // Target based on if it is an archive or single assembly
  444. // zip archives are assumed to contain directory structures relative to our ProgramDataPath
  445. var extension = Path.GetExtension(package.targetFilename);
  446. var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
  447. if (target == null)
  448. {
  449. target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
  450. }
  451. // Download to temporary file so that, if interrupted, it won't destroy the existing installation
  452. var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
  453. {
  454. Url = package.sourceUrl,
  455. CancellationToken = cancellationToken,
  456. Progress = progress
  457. }).ConfigureAwait(false);
  458. cancellationToken.ThrowIfCancellationRequested();
  459. // Validate with a checksum
  460. var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
  461. if (!packageChecksum.Equals(Guid.Empty)) // support for legacy uploads for now
  462. {
  463. using (var stream = File.OpenRead(tempFile))
  464. {
  465. var check = Guid.Parse(BitConverter.ToString(_cryptographyProvider.ComputeMD5(stream)).Replace("-", string.Empty));
  466. if (check != packageChecksum)
  467. {
  468. throw new Exception(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
  469. }
  470. }
  471. }
  472. cancellationToken.ThrowIfCancellationRequested();
  473. // Success - move it to the real target
  474. try
  475. {
  476. Directory.CreateDirectory(Path.GetDirectoryName(target));
  477. File.Copy(tempFile, target, true);
  478. //If it is an archive - write out a version file so we know what it is
  479. if (isArchive)
  480. {
  481. File.WriteAllText(target + ".ver", package.versionStr);
  482. }
  483. }
  484. catch (IOException ex)
  485. {
  486. _logger.LogError(ex, "Error attempting to move file from {TempFile} to {TargetFile}", tempFile, target);
  487. throw;
  488. }
  489. try
  490. {
  491. _fileSystem.DeleteFile(tempFile);
  492. }
  493. catch (IOException ex)
  494. {
  495. // Don't fail because of this
  496. _logger.LogError(ex, "Error deleting temp file {TempFile}", tempFile);
  497. }
  498. }
  499. /// <summary>
  500. /// Uninstalls a plugin
  501. /// </summary>
  502. /// <param name="plugin">The plugin.</param>
  503. /// <exception cref="ArgumentException"></exception>
  504. public void UninstallPlugin(IPlugin plugin)
  505. {
  506. plugin.OnUninstalling();
  507. // Remove it the quick way for now
  508. _applicationHost.RemovePlugin(plugin);
  509. var path = plugin.AssemblyFilePath;
  510. _logger.LogInformation("Deleting plugin file {0}", path);
  511. // Make this case-insensitive to account for possible incorrect assembly naming
  512. var file = _fileSystem.GetFilePaths(Path.GetDirectoryName(path))
  513. .FirstOrDefault(i => string.Equals(i, path, StringComparison.OrdinalIgnoreCase));
  514. if (!string.IsNullOrWhiteSpace(file))
  515. {
  516. path = file;
  517. }
  518. _fileSystem.DeleteFile(path);
  519. var list = _config.Configuration.UninstalledPlugins.ToList();
  520. var filename = Path.GetFileName(path);
  521. if (!list.Contains(filename, StringComparer.OrdinalIgnoreCase))
  522. {
  523. list.Add(filename);
  524. _config.Configuration.UninstalledPlugins = list.ToArray();
  525. _config.SaveConfiguration();
  526. }
  527. OnPluginUninstalled(plugin);
  528. _applicationHost.NotifyPendingRestart();
  529. }
  530. /// <summary>
  531. /// Releases unmanaged and - optionally - managed resources.
  532. /// </summary>
  533. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  534. protected virtual void Dispose(bool dispose)
  535. {
  536. if (dispose)
  537. {
  538. lock (CurrentInstallations)
  539. {
  540. foreach (var tuple in CurrentInstallations)
  541. {
  542. tuple.Item2.Dispose();
  543. }
  544. CurrentInstallations.Clear();
  545. }
  546. }
  547. }
  548. public void Dispose()
  549. {
  550. Dispose(true);
  551. }
  552. }
  553. }