InstallationManager.cs 25 KB

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