InstallationManager.cs 26 KB

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