mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-22 16:54:46 +03:00
Created IConfigurationManager
This commit is contained in:
@@ -1,37 +1,57 @@
|
||||
using System;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Security;
|
||||
using MediaBrowser.Common.Updates;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Updates;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Security;
|
||||
using MediaBrowser.Common.Updates;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Updates;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Updates
|
||||
{
|
||||
public class PackageManager : IPackageManager
|
||||
{
|
||||
public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(IHttpClient client,
|
||||
INetworkManager networkManager,
|
||||
ISecurityManager securityManager,
|
||||
ResourcePool resourcePool,
|
||||
IJsonSerializer serializer,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var data = new Dictionary<string, string> { { "key", securityManager.SupporterKey }, { "mac", networkManager.GetMacAddress() } };
|
||||
private readonly ISecurityManager _securityManager;
|
||||
private readonly INetworkManager _networkManager;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
using (var json = await client.Post(Constants.Constants.MBAdminUrl + "service/package/retrieveall", data, resourcePool.Mb, cancellationToken).ConfigureAwait(false))
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PackageManager" /> class.
|
||||
/// </summary>
|
||||
/// <param name="securityManager">The security manager.</param>
|
||||
/// <param name="networkManager">The network manager.</param>
|
||||
/// <param name="httpClient">The HTTP client.</param>
|
||||
/// <param name="applicationPaths">The application paths.</param>
|
||||
/// <param name="jsonSerializer">The json serializer.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public PackageManager(ISecurityManager securityManager, INetworkManager networkManager, IHttpClient httpClient, IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger)
|
||||
{
|
||||
_securityManager = securityManager;
|
||||
_networkManager = networkManager;
|
||||
_httpClient = httpClient;
|
||||
_appPaths = applicationPaths;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken)
|
||||
{
|
||||
var data = new Dictionary<string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } };
|
||||
|
||||
using (var json = await _httpClient.Post(Constants.Constants.MBAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var packages = serializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
|
||||
var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();
|
||||
foreach (var package in packages)
|
||||
{
|
||||
package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
|
||||
@@ -43,15 +63,15 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||
|
||||
}
|
||||
|
||||
public async Task InstallPackage(IHttpClient client, ILogger logger, ResourcePool resourcePool, IProgress<double> progress, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken)
|
||||
public async Task InstallPackage(IProgress<double> progress, PackageVersionInfo package, 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.targetFilename), ".zip", StringComparison.OrdinalIgnoreCase);
|
||||
var target = Path.Combine(isArchive ? appPaths.TempUpdatePath : appPaths.PluginsPath, package.targetFilename);
|
||||
var target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
|
||||
|
||||
// Download to temporary file so that, if interrupted, it won't destroy the existing installation
|
||||
var tempFile = await client.GetTempFile(package.sourceUrl, resourcePool.Mb, cancellationToken, progress).ConfigureAwait(false);
|
||||
var tempFile = await _httpClient.GetTempFile(package.sourceUrl, cancellationToken, progress).ConfigureAwait(false);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -79,7 +99,7 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
|
||||
_logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user