mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-27 03:04:49 +03:00
Update to 3.5.2 and .net core 2.1
This commit is contained in:
@@ -19,6 +19,7 @@ using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Updates;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
||||
namespace Emby.Server.Implementations.Updates
|
||||
{
|
||||
@@ -111,7 +112,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly ISecurityManager _securityManager;
|
||||
private readonly IConfigurationManager _config;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
/// <summary>
|
||||
@@ -125,7 +126,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
// netframework or netcore
|
||||
private readonly string _packageRuntime;
|
||||
|
||||
public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, IConfigurationManager config, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, string packageRuntime)
|
||||
public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, IServerConfigurationManager config, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, string packageRuntime)
|
||||
{
|
||||
if (logger == null)
|
||||
{
|
||||
@@ -189,7 +190,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var packages = _jsonSerializer.DeserializeFromStream<PackageInfo[]>(json);
|
||||
var packages = await _jsonSerializer.DeserializeFromStreamAsync<PackageInfo[]>(json).ConfigureAwait(false);
|
||||
|
||||
return FilterPackages(packages, packageType, applicationVersion);
|
||||
}
|
||||
@@ -203,8 +204,6 @@ namespace Emby.Server.Implementations.Updates
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime _lastPackageUpdateTime;
|
||||
|
||||
/// <summary>
|
||||
/// Gets all available packages.
|
||||
/// </summary>
|
||||
@@ -212,77 +211,21 @@ namespace Emby.Server.Implementations.Updates
|
||||
/// <returns>Task{List{PackageInfo}}.</returns>
|
||||
public async Task<List<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Info("Opening {0}", PackageCachePath);
|
||||
try
|
||||
using (var response = await _httpClient.SendAsync(new HttpRequestOptions
|
||||
{
|
||||
using (var stream = _fileSystem.OpenRead(PackageCachePath))
|
||||
Url = "https://www.mb3admin.com/admin/service/EmbyPackages.json",
|
||||
CancellationToken = cancellationToken,
|
||||
Progress = new SimpleProgress<Double>(),
|
||||
CacheLength = GetCacheLength(),
|
||||
CacheMode = CacheMode.Unconditional
|
||||
|
||||
}, "GET").ConfigureAwait(false))
|
||||
{
|
||||
using (var stream = response.Content)
|
||||
{
|
||||
var packages = _jsonSerializer.DeserializeFromStream<PackageInfo[]>(stream);
|
||||
|
||||
if (DateTime.UtcNow - _lastPackageUpdateTime > GetCacheLength())
|
||||
{
|
||||
UpdateCachedPackages(CancellationToken.None, false);
|
||||
}
|
||||
|
||||
return FilterPackages(packages);
|
||||
return FilterPackages(await _jsonSerializer.DeserializeFromStreamAsync<PackageInfo[]>(stream).ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
_lastPackageUpdateTime = DateTime.MinValue;
|
||||
await UpdateCachedPackages(cancellationToken, true).ConfigureAwait(false);
|
||||
using (var stream = _fileSystem.OpenRead(PackageCachePath))
|
||||
{
|
||||
return FilterPackages(_jsonSerializer.DeserializeFromStream<PackageInfo[]>(stream));
|
||||
}
|
||||
}
|
||||
|
||||
private string PackageCachePath
|
||||
{
|
||||
get { return Path.Combine(_appPaths.CachePath, "serverpackages.json"); }
|
||||
}
|
||||
|
||||
private readonly SemaphoreSlim _updateSemaphore = new SemaphoreSlim(1, 1);
|
||||
private async Task UpdateCachedPackages(CancellationToken cancellationToken, bool throwErrors)
|
||||
{
|
||||
await _updateSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
if (DateTime.UtcNow - _lastPackageUpdateTime < GetCacheLength())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
|
||||
{
|
||||
Url = "https://www.mb3admin.com/admin/service/EmbyPackages.json",
|
||||
CancellationToken = cancellationToken,
|
||||
Progress = new SimpleProgress<Double>()
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(PackageCachePath));
|
||||
|
||||
_fileSystem.CopyFile(tempFile, PackageCachePath, true);
|
||||
_lastPackageUpdateTime = DateTime.UtcNow;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating package cache", ex);
|
||||
|
||||
if (throwErrors)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_updateSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private PackageVersionClass GetSystemUpdateLevel()
|
||||
@@ -304,12 +247,12 @@ namespace Emby.Server.Implementations.Updates
|
||||
var versions = new List<PackageVersionInfo>();
|
||||
foreach (var version in package.versions)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(version.sourceUrl))
|
||||
if (string.IsNullOrEmpty(version.sourceUrl))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
|
||||
if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -339,7 +282,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
|
||||
var returnList = new List<PackageInfo>();
|
||||
|
||||
var filterOnPackageType = !string.IsNullOrWhiteSpace(packageType);
|
||||
var filterOnPackageType = !string.IsNullOrEmpty(packageType);
|
||||
|
||||
foreach (var p in packagesList)
|
||||
{
|
||||
@@ -465,7 +408,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
return latestPluginInfo != null && GetPackageVersion(latestPluginInfo) > p.Version ? latestPluginInfo : null;
|
||||
|
||||
}).Where(i => i != null)
|
||||
.Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
|
||||
.Where(p => !string.IsNullOrEmpty(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -491,7 +434,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
|
||||
var installationInfo = new InstallationInfo
|
||||
{
|
||||
Id = Guid.NewGuid().ToString("N"),
|
||||
Id = Guid.NewGuid(),
|
||||
Name = package.name,
|
||||
AssemblyGuid = package.guid,
|
||||
UpdateClass = package.classification,
|
||||
@@ -575,7 +518,6 @@ namespace Emby.Server.Implementations.Updates
|
||||
finally
|
||||
{
|
||||
// Dispose the progress object and remove the installation from the in-progress list
|
||||
innerProgress.Dispose();
|
||||
tuple.Item2.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -590,16 +532,23 @@ namespace Emby.Server.Implementations.Updates
|
||||
/// <returns>Task.</returns>
|
||||
private async Task InstallPackageInternal(PackageVersionInfo package, bool isPlugin, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
IPlugin plugin = null;
|
||||
|
||||
if (isPlugin)
|
||||
{
|
||||
// Set last update time if we were installed before
|
||||
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));
|
||||
}
|
||||
|
||||
string targetPath = plugin == null ? null : plugin.AssemblyFilePath;
|
||||
|
||||
// Do the install
|
||||
await PerformPackageInstallation(progress, package, cancellationToken).ConfigureAwait(false);
|
||||
await PerformPackageInstallation(progress, targetPath, package, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Do plugin-specific processing
|
||||
if (isPlugin)
|
||||
{
|
||||
// Set last update time if we were installed before
|
||||
var 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));
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
OnPluginUpdated(plugin, package);
|
||||
@@ -611,13 +560,17 @@ namespace Emby.Server.Implementations.Updates
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PerformPackageInstallation(IProgress<double> progress, PackageVersionInfo package, CancellationToken cancellationToken)
|
||||
private async Task PerformPackageInstallation(IProgress<double> progress, string target, 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 extension = Path.GetExtension(package.targetFilename);
|
||||
var isArchive = string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase);
|
||||
var target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
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 _httpClient.GetTempFile(new HttpRequestOptions
|
||||
@@ -632,7 +585,7 @@ namespace Emby.Server.Implementations.Updates
|
||||
|
||||
// Validate with a checksum
|
||||
var packageChecksum = string.IsNullOrWhiteSpace(package.checksum) ? Guid.Empty : new Guid(package.checksum);
|
||||
if (packageChecksum != Guid.Empty) // support for legacy uploads for now
|
||||
if (!packageChecksum.Equals(Guid.Empty)) // support for legacy uploads for now
|
||||
{
|
||||
using (var stream = _fileSystem.OpenRead(tempFile))
|
||||
{
|
||||
@@ -700,6 +653,15 @@ namespace Emby.Server.Implementations.Updates
|
||||
|
||||
_fileSystem.DeleteFile(path);
|
||||
|
||||
var list = _config.Configuration.UninstalledPlugins.ToList();
|
||||
var filename = Path.GetFileName(path);
|
||||
if (!list.Contains(filename, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
list.Add(filename);
|
||||
_config.Configuration.UninstalledPlugins = list.ToArray();
|
||||
_config.SaveConfiguration();
|
||||
}
|
||||
|
||||
OnPluginUninstalled(plugin);
|
||||
|
||||
_applicationHost.NotifyPendingRestart();
|
||||
@@ -728,7 +690,6 @@ namespace Emby.Server.Implementations.Updates
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user