InstallationManager.cs 25 KB

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