|
@@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Updates
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Manages all install, uninstall and update operations (both plugins and system)
|
|
/// Manages all install, uninstall and update operations (both plugins and system)
|
|
/// </summary>
|
|
/// </summary>
|
|
- public class InstallationManager : BaseManager<Kernel>, IInstallationManager
|
|
|
|
|
|
+ public class InstallationManager : BaseManager<Kernel>
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The current installations
|
|
/// The current installations
|
|
@@ -109,6 +109,11 @@ namespace MediaBrowser.Controller.Updates
|
|
/// </summary>
|
|
/// </summary>
|
|
private readonly INetworkManager _networkManager;
|
|
private readonly INetworkManager _networkManager;
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// The package manager
|
|
|
|
+ /// </summary>
|
|
|
|
+ private readonly IPackageManager _packageManager;
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the json serializer.
|
|
/// Gets the json serializer.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -134,11 +139,12 @@ namespace MediaBrowser.Controller.Updates
|
|
/// <param name="httpClient">The HTTP client.</param>
|
|
/// <param name="httpClient">The HTTP client.</param>
|
|
/// <param name="zipClient">The zip client.</param>
|
|
/// <param name="zipClient">The zip client.</param>
|
|
/// <param name="networkManager">The network manager.</param>
|
|
/// <param name="networkManager">The network manager.</param>
|
|
|
|
+ /// <param name="packageManager">The package manager.</param>
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
|
/// <param name="logger">The logger.</param>
|
|
/// <param name="logger">The logger.</param>
|
|
/// <param name="appHost">The app host.</param>
|
|
/// <param name="appHost">The app host.</param>
|
|
/// <exception cref="System.ArgumentNullException">zipClient</exception>
|
|
/// <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)
|
|
: base(kernel)
|
|
{
|
|
{
|
|
if (zipClient == null)
|
|
if (zipClient == null)
|
|
@@ -149,6 +155,10 @@ namespace MediaBrowser.Controller.Updates
|
|
{
|
|
{
|
|
throw new ArgumentNullException("networkManager");
|
|
throw new ArgumentNullException("networkManager");
|
|
}
|
|
}
|
|
|
|
+ if (packageManager == null)
|
|
|
|
+ {
|
|
|
|
+ throw new ArgumentNullException("packageManager");
|
|
|
|
+ }
|
|
if (logger == null)
|
|
if (logger == null)
|
|
{
|
|
{
|
|
throw new ArgumentNullException("logger");
|
|
throw new ArgumentNullException("logger");
|
|
@@ -168,6 +178,7 @@ namespace MediaBrowser.Controller.Updates
|
|
HttpClient = httpClient;
|
|
HttpClient = httpClient;
|
|
ApplicationHost = appHost;
|
|
ApplicationHost = appHost;
|
|
_networkManager = networkManager;
|
|
_networkManager = networkManager;
|
|
|
|
+ _packageManager = packageManager;
|
|
_logger = logger;
|
|
_logger = logger;
|
|
ZipClient = zipClient;
|
|
ZipClient = zipClient;
|
|
}
|
|
}
|
|
@@ -183,39 +194,26 @@ namespace MediaBrowser.Controller.Updates
|
|
PackageType? packageType = null,
|
|
PackageType? packageType = null,
|
|
Version applicationVersion = 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)
|
|
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>
|
|
/// <summary>
|
|
@@ -431,77 +429,31 @@ namespace MediaBrowser.Controller.Updates
|
|
/// <returns>Task.</returns>
|
|
/// <returns>Task.</returns>
|
|
private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
|
|
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);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|