aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Updates/InstallationManager.cs
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-27 11:57:14 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-27 11:57:14 -0500
commit6d5d291762c050e0f5598f45b837e45f270d600f (patch)
treebb6d6fe204d7e9c8b6a9502b2604202cc7849c92 /MediaBrowser.Controller/Updates/InstallationManager.cs
parentca7ee684730fe0d99a6160659c679c36a1646c88 (diff)
parent1d51ede06056a54099616d0f52fdf8150c510e50 (diff)
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Conflicts: MediaBrowser.Common.Implementations/BaseApplicationHost.cs MediaBrowser.ServerApplication/ApplicationHost.cs
Diffstat (limited to 'MediaBrowser.Controller/Updates/InstallationManager.cs')
-rw-r--r--MediaBrowser.Controller/Updates/InstallationManager.cs130
1 files changed, 41 insertions, 89 deletions
diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs
index 633cc6bc3..7765b8aef 100644
--- a/MediaBrowser.Controller/Updates/InstallationManager.cs
+++ b/MediaBrowser.Controller/Updates/InstallationManager.cs
@@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Updates
/// <summary>
/// Manages all install, uninstall and update operations (both plugins and system)
/// </summary>
- public class InstallationManager : BaseManager<Kernel>, IInstallationManager
+ public class InstallationManager : BaseManager<Kernel>
{
/// <summary>
/// The current installations
@@ -110,6 +110,11 @@ namespace MediaBrowser.Controller.Updates
private readonly INetworkManager _networkManager;
/// <summary>
+ /// The package manager
+ /// </summary>
+ private readonly IPackageManager _packageManager;
+
+ /// <summary>
/// Gets the json serializer.
/// </summary>
/// <value>The json serializer.</value>
@@ -134,11 +139,12 @@ namespace MediaBrowser.Controller.Updates
/// <param name="httpClient">The HTTP client.</param>
/// <param name="zipClient">The zip client.</param>
/// <param name="networkManager">The network manager.</param>
+ /// <param name="packageManager">The package manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logger">The logger.</param>
/// <param name="appHost">The app host.</param>
/// <exception cref="System.ArgumentNullException">zipClient</exception>
- public InstallationManager(Kernel kernel, IHttpClient httpClient, IZipClient zipClient, INetworkManager networkManager, IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost)
+ public InstallationManager(Kernel kernel, IHttpClient httpClient, IZipClient zipClient, INetworkManager networkManager, IPackageManager packageManager, IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost)
: base(kernel)
{
if (zipClient == null)
@@ -149,6 +155,10 @@ namespace MediaBrowser.Controller.Updates
{
throw new ArgumentNullException("networkManager");
}
+ if (packageManager == null)
+ {
+ throw new ArgumentNullException("packageManager");
+ }
if (logger == null)
{
throw new ArgumentNullException("logger");
@@ -168,6 +178,7 @@ namespace MediaBrowser.Controller.Updates
HttpClient = httpClient;
ApplicationHost = appHost;
_networkManager = networkManager;
+ _packageManager = packageManager;
_logger = logger;
ZipClient = zipClient;
}
@@ -183,39 +194,26 @@ namespace MediaBrowser.Controller.Updates
PackageType? packageType = null,
Version applicationVersion = null)
{
- var data = new Dictionary<string, string> { { "key", Kernel.SecurityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } };
+ var packages = (await _packageManager.GetAvailablePackages(HttpClient, _networkManager, Kernel.SecurityManager, Kernel.ResourcePools, JsonSerializer, cancellationToken).ConfigureAwait(false)).ToList();
- using (var json = await HttpClient.Post(Controller.Kernel.MBAdminUrl + "service/package/retrieveall", data, Kernel.ResourcePools.Mb, cancellationToken).ConfigureAwait(false))
+ if (packageType.HasValue)
{
- cancellationToken.ThrowIfCancellationRequested();
-
- var packages = JsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
+ packages = packages.Where(p => p.type == packageType.Value).ToList();
+ }
+ // If an app version was supplied, filter the versions for each package to only include supported versions
+ if (applicationVersion != null)
+ {
foreach (var package in packages)
{
- package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
- .OrderByDescending(v => v.version).ToList();
- }
-
- if (packageType.HasValue)
- {
- packages = packages.Where(p => p.type == packageType.Value).ToList();
- }
-
- // If an app version was supplied, filter the versions for each package to only include supported versions
- if (applicationVersion != null)
- {
- foreach (var package in packages)
- {
- package.versions = package.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToList();
- }
+ package.versions = package.versions.Where(v => IsPackageVersionUpToDate(v, applicationVersion)).ToList();
}
+ }
- // Remove packages with no versions
- packages = packages.Where(p => p.versions.Any()).ToList();
+ // Remove packages with no versions
+ packages = packages.Where(p => p.versions.Any()).ToList();
- return packages;
- }
+ return packages;
}
/// <summary>
@@ -431,77 +429,31 @@ namespace MediaBrowser.Controller.Updates
/// <returns>Task.</returns>
private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
{
- // Target based on if it is an archive or single assembly
- // zip archives are assumed to contain directory structures relative to our ProgramDataPath
- var isArchive = string.Equals(Path.GetExtension(package.sourceUrl), ".zip", StringComparison.OrdinalIgnoreCase);
- var target = isArchive ? Kernel.ApplicationPaths.ProgramDataPath : Path.Combine(Kernel.ApplicationPaths.PluginsPath, package.targetFilename);
-
- // Download to temporary file so that, if interrupted, it won't destroy the existing installation
- var tempFile = await HttpClient.GetTempFile(package.sourceUrl, Kernel.ResourcePools.Mb, cancellationToken, progress).ConfigureAwait(false);
+ // Do the install
+ await _packageManager.InstallPackage(HttpClient, _logger, Kernel.ResourcePools, progress, ZipClient, Kernel.ApplicationPaths, package, cancellationToken).ConfigureAwait(false);
- cancellationToken.ThrowIfCancellationRequested();
-
- // Validate with a checksum
- if (package.checksum != Guid.Empty) // support for legacy uploads for now
+ // Do plugin-specific processing
+ if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
- using (var crypto = new MD5CryptoServiceProvider())
- using (var stream = new BufferedStream(File.OpenRead(tempFile), 100000))
+ // Set last update time if we were installed before
+ var plugin = Kernel.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
+
+ if (plugin != null)
{
- var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
- if (check != package.checksum)
+ // Synchronize the UpdateClass value
+ if (plugin.Configuration.UpdateClass != package.classification)
{
- throw new ApplicationException(string.Format("Download validation failed for {0}. Probably corrupted during transfer.", package.name));
+ plugin.Configuration.UpdateClass = package.classification;
+ plugin.SaveConfiguration();
}
- }
- }
-
- cancellationToken.ThrowIfCancellationRequested();
- // Success - move it to the real target based on type
- if (isArchive)
- {
- try
- {
- ZipClient.ExtractAll(tempFile, target, true);
+ OnPluginUpdated(plugin, package);
}
- catch (IOException e)
+ else
{
- _logger.ErrorException("Error attempting to extract archive from {0} to {1}", e, tempFile, target);
- throw;
+ OnPluginInstalled(package);
}
-
- }
- else
- {
- try
- {
- File.Copy(tempFile, target, true);
- File.Delete(tempFile);
- }
- catch (IOException e)
- {
- _logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
- throw;
- }
- }
-
- // Set last update time if we were installed before
- var plugin = Kernel.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
-
- if (plugin != null)
- {
- // Synchronize the UpdateClass value
- if (plugin.Configuration.UpdateClass != package.classification)
- {
- plugin.Configuration.UpdateClass = package.classification;
- plugin.SaveConfiguration();
- }
-
- OnPluginUpdated(plugin, package);
- }
- else
- {
- OnPluginInstalled(package);
+
}
}