|
@@ -1,4 +1,5 @@
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
@@ -97,25 +98,25 @@ namespace Emby.Server.Implementations.Updates
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<InstallationEventArgs> PackageInstalling;
|
|
|
+ public event EventHandler<InstallationInfo> PackageInstalling;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
|
|
|
+ public event EventHandler<InstallationInfo> PackageInstallationCompleted;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
|
|
|
+ public event EventHandler<InstallationInfo> PackageInstallationCancelled;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
|
|
|
+ public event EventHandler<IPlugin> PluginUninstalled;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<GenericEventArgs<(IPlugin, VersionInfo)>> PluginUpdated;
|
|
|
+ public event EventHandler<InstallationInfo> PluginUpdated;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public event EventHandler<GenericEventArgs<VersionInfo>> PluginInstalled;
|
|
|
+ public event EventHandler<InstallationInfo> PluginInstalled;
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
|
|
@@ -183,24 +184,7 @@ namespace Emby.Server.Implementations.Updates
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public IEnumerable<VersionInfo> GetCompatibleVersions(
|
|
|
- IEnumerable<VersionInfo> availableVersions,
|
|
|
- Version minVersion = null)
|
|
|
- {
|
|
|
- var appVer = _applicationHost.ApplicationVersion;
|
|
|
- availableVersions = availableVersions
|
|
|
- .Where(x => Version.Parse(x.targetAbi) <= appVer);
|
|
|
-
|
|
|
- if (minVersion != null)
|
|
|
- {
|
|
|
- availableVersions = availableVersions.Where(x => x.version >= minVersion);
|
|
|
- }
|
|
|
-
|
|
|
- return availableVersions.OrderByDescending(x => x.version);
|
|
|
- }
|
|
|
-
|
|
|
- /// <inheritdoc />
|
|
|
- public IEnumerable<VersionInfo> GetCompatibleVersions(
|
|
|
+ public IEnumerable<InstallationInfo> GetCompatibleVersions(
|
|
|
IEnumerable<PackageInfo> availablePackages,
|
|
|
string name = null,
|
|
|
Guid guid = default,
|
|
@@ -211,28 +195,46 @@ namespace Emby.Server.Implementations.Updates
|
|
|
// Package not found in repository
|
|
|
if (package == null)
|
|
|
{
|
|
|
- return Enumerable.Empty<VersionInfo>();
|
|
|
+ yield break;
|
|
|
+ }
|
|
|
+
|
|
|
+ var appVer = _applicationHost.ApplicationVersion;
|
|
|
+ var availableVersions = package.versions
|
|
|
+ .Where(x => Version.Parse(x.targetAbi) <= appVer);
|
|
|
+
|
|
|
+ if (minVersion != null)
|
|
|
+ {
|
|
|
+ availableVersions = availableVersions
|
|
|
+ .Where(x => new Version(x.version) >= minVersion)
|
|
|
+ .OrderByDescending(x => x.version);
|
|
|
}
|
|
|
|
|
|
- return GetCompatibleVersions(
|
|
|
- package.versions,
|
|
|
- minVersion);
|
|
|
+ foreach (var v in availableVersions)
|
|
|
+ {
|
|
|
+ yield return new InstallationInfo
|
|
|
+ {
|
|
|
+ Changelog = v.changelog,
|
|
|
+ Guid = new Guid(package.guid),
|
|
|
+ Name = package.name,
|
|
|
+ Version = new Version(v.version)
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public async Task<IEnumerable<VersionInfo>> GetAvailablePluginUpdates(CancellationToken cancellationToken = default)
|
|
|
+ public async Task<IEnumerable<InstallationInfo>> GetAvailablePluginUpdates(CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false);
|
|
|
return GetAvailablePluginUpdates(catalog);
|
|
|
}
|
|
|
|
|
|
- private IEnumerable<VersionInfo> GetAvailablePluginUpdates(IReadOnlyList<PackageInfo> pluginCatalog)
|
|
|
+ private IEnumerable<InstallationInfo> GetAvailablePluginUpdates(IReadOnlyList<PackageInfo> pluginCatalog)
|
|
|
{
|
|
|
foreach (var plugin in _applicationHost.Plugins)
|
|
|
{
|
|
|
var compatibleversions = GetCompatibleVersions(pluginCatalog, plugin.Name, plugin.Id, plugin.Version);
|
|
|
- var version = compatibleversions.FirstOrDefault(y => y.version > plugin.Version);
|
|
|
- if (version != null && !CompletedInstallations.Any(x => string.Equals(x.Guid, version.guid, StringComparison.OrdinalIgnoreCase)))
|
|
|
+ var version = compatibleversions.FirstOrDefault(y => y.Version > plugin.Version);
|
|
|
+ if (version != null && CompletedInstallations.All(x => x.Guid != version.Guid))
|
|
|
{
|
|
|
yield return version;
|
|
|
}
|
|
@@ -240,23 +242,16 @@ namespace Emby.Server.Implementations.Updates
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
- public async Task InstallPackage(VersionInfo package, CancellationToken cancellationToken)
|
|
|
+ public async Task InstallPackage(InstallationInfo package, CancellationToken cancellationToken)
|
|
|
{
|
|
|
if (package == null)
|
|
|
{
|
|
|
throw new ArgumentNullException(nameof(package));
|
|
|
}
|
|
|
|
|
|
- var installationInfo = new InstallationInfo
|
|
|
- {
|
|
|
- Guid = package.guid,
|
|
|
- Name = package.name,
|
|
|
- Version = package.version.ToString()
|
|
|
- };
|
|
|
-
|
|
|
var innerCancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
|
- var tuple = (installationInfo, innerCancellationTokenSource);
|
|
|
+ var tuple = (package, innerCancellationTokenSource);
|
|
|
|
|
|
// Add it to the in-progress list
|
|
|
lock (_currentInstallationsLock)
|
|
@@ -266,13 +261,7 @@ namespace Emby.Server.Implementations.Updates
|
|
|
|
|
|
var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
|
|
|
|
|
|
- var installationEventArgs = new InstallationEventArgs
|
|
|
- {
|
|
|
- InstallationInfo = installationInfo,
|
|
|
- VersionInfo = package
|
|
|
- };
|
|
|
-
|
|
|
- PackageInstalling?.Invoke(this, installationEventArgs);
|
|
|
+ PackageInstalling?.Invoke(this, package);
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -283,9 +272,9 @@ namespace Emby.Server.Implementations.Updates
|
|
|
_currentInstallations.Remove(tuple);
|
|
|
}
|
|
|
|
|
|
- _completedInstallationsInternal.Add(installationInfo);
|
|
|
+ _completedInstallationsInternal.Add(package);
|
|
|
|
|
|
- PackageInstallationCompleted?.Invoke(this, installationEventArgs);
|
|
|
+ PackageInstallationCompleted?.Invoke(this, package);
|
|
|
}
|
|
|
catch (OperationCanceledException)
|
|
|
{
|
|
@@ -294,9 +283,9 @@ namespace Emby.Server.Implementations.Updates
|
|
|
_currentInstallations.Remove(tuple);
|
|
|
}
|
|
|
|
|
|
- _logger.LogInformation("Package installation cancelled: {0} {1}", package.name, package.version);
|
|
|
+ _logger.LogInformation("Package installation cancelled: {0} {1}", package.Name, package.Version);
|
|
|
|
|
|
- PackageInstallationCancelled?.Invoke(this, installationEventArgs);
|
|
|
+ PackageInstallationCancelled?.Invoke(this, package);
|
|
|
|
|
|
throw;
|
|
|
}
|
|
@@ -311,7 +300,7 @@ namespace Emby.Server.Implementations.Updates
|
|
|
|
|
|
PackageInstallationFailed?.Invoke(this, new InstallationFailedEventArgs
|
|
|
{
|
|
|
- InstallationInfo = installationInfo,
|
|
|
+ InstallationInfo = package,
|
|
|
Exception = ex
|
|
|
});
|
|
|
|
|
@@ -330,11 +319,11 @@ namespace Emby.Server.Implementations.Updates
|
|
|
/// <param name="package">The package.</param>
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
/// <returns><see cref="Task" />.</returns>
|
|
|
- private async Task InstallPackageInternal(VersionInfo package, CancellationToken cancellationToken)
|
|
|
+ private async Task InstallPackageInternal(InstallationInfo package, CancellationToken cancellationToken)
|
|
|
{
|
|
|
// Set last update time if we were installed before
|
|
|
- IPlugin plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase))
|
|
|
- ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));
|
|
|
+ IPlugin plugin = _applicationHost.Plugins.FirstOrDefault(p => p.Id == package.Guid)
|
|
|
+ ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.Name, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
// Do the install
|
|
|
await PerformPackageInstallation(package, cancellationToken).ConfigureAwait(false);
|
|
@@ -342,38 +331,38 @@ namespace Emby.Server.Implementations.Updates
|
|
|
// Do plugin-specific processing
|
|
|
if (plugin == null)
|
|
|
{
|
|
|
- _logger.LogInformation("New plugin installed: {0} {1} {2}", package.name, package.version);
|
|
|
+ _logger.LogInformation("New plugin installed: {0} {1} {2}", package.Name, package.Version);
|
|
|
|
|
|
- PluginInstalled?.Invoke(this, new GenericEventArgs<VersionInfo>(package));
|
|
|
+ PluginInstalled?.Invoke(this, package);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _logger.LogInformation("Plugin updated: {0} {1} {2}", package.name, package.version);
|
|
|
+ _logger.LogInformation("Plugin updated: {0} {1} {2}", package.Name, package.Version);
|
|
|
|
|
|
- PluginUpdated?.Invoke(this, new GenericEventArgs<(IPlugin, VersionInfo)>((plugin, package)));
|
|
|
+ PluginUpdated?.Invoke(this, package);
|
|
|
}
|
|
|
|
|
|
_applicationHost.NotifyPendingRestart();
|
|
|
}
|
|
|
|
|
|
- private async Task PerformPackageInstallation(VersionInfo package, CancellationToken cancellationToken)
|
|
|
+ private async Task PerformPackageInstallation(InstallationInfo package, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- var extension = Path.GetExtension(package.filename);
|
|
|
+ var extension = Path.GetExtension(package.SourceUrl);
|
|
|
if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
- _logger.LogError("Only zip packages are supported. {Filename} is not a zip archive.", package.filename);
|
|
|
+ _logger.LogError("Only zip packages are supported. {Filename} is not a zip archive.", package.SourceUrl);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Always override the passed-in target (which is a file) and figure it out again
|
|
|
- string targetDir = Path.Combine(_appPaths.PluginsPath, package.name);
|
|
|
+ string targetDir = Path.Combine(_appPaths.PluginsPath, package.Name);
|
|
|
|
|
|
// CA5351: Do Not Use Broken Cryptographic Algorithms
|
|
|
#pragma warning disable CA5351
|
|
|
using (var res = await _httpClient.SendAsync(
|
|
|
new HttpRequestOptions
|
|
|
{
|
|
|
- Url = package.sourceUrl,
|
|
|
+ Url = package.SourceUrl,
|
|
|
CancellationToken = cancellationToken,
|
|
|
// We need it to be buffered for setting the position
|
|
|
BufferContent = true
|
|
@@ -385,12 +374,12 @@ namespace Emby.Server.Implementations.Updates
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
var hash = Hex.Encode(md5.ComputeHash(stream));
|
|
|
- if (!string.Equals(package.checksum, hash, StringComparison.OrdinalIgnoreCase))
|
|
|
+ if (!string.Equals(package.Checksum, hash, StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
_logger.LogError(
|
|
|
"The checksums didn't match while installing {Package}, expected: {Expected}, got: {Received}",
|
|
|
- package.name,
|
|
|
- package.checksum,
|
|
|
+ package.Name,
|
|
|
+ package.Checksum,
|
|
|
hash);
|
|
|
throw new InvalidDataException("The checksum of the received data doesn't match.");
|
|
|
}
|
|
@@ -456,7 +445,7 @@ namespace Emby.Server.Implementations.Updates
|
|
|
_config.SaveConfiguration();
|
|
|
}
|
|
|
|
|
|
- PluginUninstalled?.Invoke(this, new GenericEventArgs<IPlugin> { Argument = plugin });
|
|
|
+ PluginUninstalled?.Invoke(this, plugin);
|
|
|
|
|
|
_applicationHost.NotifyPendingRestart();
|
|
|
}
|
|
@@ -466,7 +455,7 @@ namespace Emby.Server.Implementations.Updates
|
|
|
{
|
|
|
lock (_currentInstallationsLock)
|
|
|
{
|
|
|
- var install = _currentInstallations.Find(x => x.info.Guid == id.ToString());
|
|
|
+ var install = _currentInstallations.Find(x => x.info.Guid == id);
|
|
|
if (install == default((InstallationInfo, CancellationTokenSource)))
|
|
|
{
|
|
|
return false;
|
|
@@ -486,9 +475,9 @@ namespace Emby.Server.Implementations.Updates
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Releases unmanaged and - optionally - managed resources.
|
|
|
+ /// Releases unmanaged and optionally managed resources.
|
|
|
/// </summary>
|
|
|
- /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
|
+ /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources or <c>false</c> to release only unmanaged resources.</param>
|
|
|
protected virtual void Dispose(bool dispose)
|
|
|
{
|
|
|
if (dispose)
|