InstallationManager.cs 26 KB

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