mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-27 10:58:44 +01:00
plugin security fixes and other abstractions
This commit is contained in:
@@ -132,7 +132,6 @@
|
||||
<Compile Include="Persistence\IRepository.cs" />
|
||||
<Compile Include="Persistence\IUserDataRepository.cs" />
|
||||
<Compile Include="Persistence\IUserRepository.cs" />
|
||||
<Compile Include="Persistence\TypeMapper.cs" />
|
||||
<Compile Include="Playback\IIntroProvider.cs" />
|
||||
<Compile Include="Plugins\IPluginConfigurationPage.cs" />
|
||||
<Compile Include="Plugins\PluginSecurityManager.cs" />
|
||||
@@ -179,10 +178,7 @@
|
||||
<Compile Include="Resolvers\TV\SeriesResolver.cs" />
|
||||
<Compile Include="Resolvers\TV\TVUtils.cs" />
|
||||
<Compile Include="Library\ResourcePool.cs" />
|
||||
<Compile Include="ScheduledTasks\ChapterImagesTask.cs" />
|
||||
<Compile Include="ScheduledTasks\ImageCleanupTask.cs" />
|
||||
<Compile Include="ScheduledTasks\PeopleValidationTask.cs" />
|
||||
<Compile Include="ScheduledTasks\PluginUpdateTask.cs" />
|
||||
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" />
|
||||
<Compile Include="Library\ItemResolveArgs.cs" />
|
||||
<Compile Include="IO\DirectoryWatchers.cs" />
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Class TypeMapper
|
||||
/// </summary>
|
||||
public class TypeMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, Type> _typeMap = new ConcurrentDictionary<string, Type>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">Name of the type.</param>
|
||||
/// <returns>Type.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public Type GetType(string typeName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
return _typeMap.GetOrAdd(typeName, LookupType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lookups the type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">Name of the type.</param>
|
||||
/// <returns>Type.</returns>
|
||||
private Type LookupType(string typeName)
|
||||
{
|
||||
return AppDomain
|
||||
.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.Select(a => a.GetType(typeName, false))
|
||||
.FirstOrDefault(t => t != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Mediabrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using Mediabrowser.Model.Entities;
|
||||
using Mediabrowser.PluginSecurity;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Common.Net;
|
||||
@@ -39,10 +40,8 @@ namespace MediaBrowser.Controller.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The _network manager
|
||||
/// </summary>
|
||||
private INetworkManager _networkManager;
|
||||
private IHttpClient _httpClient;
|
||||
private IJsonSerializer _jsonSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// The _kernel
|
||||
@@ -53,21 +52,22 @@ namespace MediaBrowser.Controller.Plugins
|
||||
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="networkManager">The network manager.</param>
|
||||
public PluginSecurityManager(IKernel kernel, INetworkManager networkManager)
|
||||
public PluginSecurityManager(IKernel kernel, IHttpClient httpClient, IJsonSerializer jsonSerializer, IApplicationPaths appPaths)
|
||||
{
|
||||
if (kernel == null)
|
||||
{
|
||||
throw new ArgumentNullException("kernel");
|
||||
}
|
||||
|
||||
if (networkManager == null)
|
||||
if (httpClient == null)
|
||||
{
|
||||
throw new ArgumentNullException("networkManager");
|
||||
throw new ArgumentNullException("httpClient");
|
||||
}
|
||||
|
||||
_kernel = kernel;
|
||||
_networkManager = networkManager;
|
||||
_httpClient = httpClient;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
MBRegistration.Init(appPaths);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,7 +78,7 @@ namespace MediaBrowser.Controller.Plugins
|
||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||
public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
|
||||
{
|
||||
return await MBRegistration.GetRegistrationStatus(feature, mb2Equivalent).ConfigureAwait(false);
|
||||
return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.ScheduledTasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ChapterImagesTask
|
||||
/// </summary>
|
||||
class ChapterImagesTask : BaseScheduledTask<Kernel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChapterImagesTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="logger"></param>
|
||||
public ChapterImagesTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
|
||||
: base(kernel, taskManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[]
|
||||
{
|
||||
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(4) }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the task to be executed
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var videos = Kernel.RootFolder.RecursiveChildren.OfType<Video>().Where(v => v.Chapters != null).ToList();
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
var tasks = videos.Select(v => Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await Kernel.FFMpegManager.PopulateChapterImages(v, cancellationToken, true, true);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error creating chapter images for {0}", ex, v.Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock (progress)
|
||||
{
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= videos.Count;
|
||||
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the task
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
{
|
||||
get { return "Create video chapter thumbnails"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
{
|
||||
get { return "Creates thumbnails for videos that have chapters."; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category.
|
||||
/// </summary>
|
||||
/// <value>The category.</value>
|
||||
public override string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Library";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.ScheduledTasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ImageCleanupTask
|
||||
/// </summary>
|
||||
public class ImageCleanupTask : BaseScheduledTask<Kernel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ImageCleanupTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="taskManager">The task manager.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public ImageCleanupTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
|
||||
: base(kernel, taskManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[]
|
||||
{
|
||||
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(2) }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the task to be executed
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected override async Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
await EnsureChapterImages(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// First gather all image files
|
||||
var files = GetFiles(Kernel.FFMpegManager.AudioImagesDataPath)
|
||||
.Concat(GetFiles(Kernel.FFMpegManager.VideoImagesDataPath))
|
||||
.Concat(GetFiles(Kernel.ProviderManager.ImagesDataPath))
|
||||
.ToList();
|
||||
|
||||
// Now gather all items
|
||||
var items = Kernel.RootFolder.RecursiveChildren.ToList();
|
||||
items.Add(Kernel.RootFolder);
|
||||
|
||||
// Determine all possible image paths
|
||||
var pathsInUse = items.SelectMany(GetPathsInUse)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(p => p, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
var tasks = files.Select(file => Task.Run(() =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (!pathsInUse.ContainsKey(file))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.ErrorException("Error deleting {0}", ex, file);
|
||||
}
|
||||
}
|
||||
|
||||
// Update progress
|
||||
lock (progress)
|
||||
{
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= files.Count;
|
||||
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
}));
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the chapter images.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private Task EnsureChapterImages(CancellationToken cancellationToken)
|
||||
{
|
||||
var videos = Kernel.RootFolder.RecursiveChildren.OfType<Video>().Where(v => v.Chapters != null).ToList();
|
||||
|
||||
var tasks = videos.Select(v => Task.Run(async () =>
|
||||
{
|
||||
await Kernel.FFMpegManager.PopulateChapterImages(v, cancellationToken, false, true);
|
||||
}));
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the paths in use.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
private IEnumerable<string> GetPathsInUse(BaseItem item)
|
||||
{
|
||||
IEnumerable<string> images = new List<string> { };
|
||||
|
||||
if (item.Images != null)
|
||||
{
|
||||
images = images.Concat(item.Images.Values);
|
||||
}
|
||||
|
||||
if (item.BackdropImagePaths != null)
|
||||
{
|
||||
images = images.Concat(item.BackdropImagePaths);
|
||||
}
|
||||
|
||||
if (item.ScreenshotImagePaths != null)
|
||||
{
|
||||
images = images.Concat(item.ScreenshotImagePaths);
|
||||
}
|
||||
|
||||
var video = item as Video;
|
||||
|
||||
if (video != null && video.Chapters != null)
|
||||
{
|
||||
images = images.Concat(video.Chapters.Where(i => !string.IsNullOrEmpty(i.ImagePath)).Select(i => i.ImagePath));
|
||||
}
|
||||
|
||||
if (item.LocalTrailers != null)
|
||||
{
|
||||
foreach (var subItem in item.LocalTrailers)
|
||||
{
|
||||
images = images.Concat(GetPathsInUse(subItem));
|
||||
}
|
||||
}
|
||||
|
||||
var movie = item as Movie;
|
||||
|
||||
if (movie != null && movie.SpecialFeatures != null)
|
||||
{
|
||||
foreach (var subItem in movie.SpecialFeatures)
|
||||
{
|
||||
images = images.Concat(GetPathsInUse(subItem));
|
||||
}
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the files.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
private IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
return Directory.EnumerateFiles(path, "*.jpg", SearchOption.AllDirectories).Concat(Directory.EnumerateFiles(path, "*.png", SearchOption.AllDirectories));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the task
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
{
|
||||
get { return "Images cleanup"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
{
|
||||
get { return "Deletes downloaded and extracted images that are no longer being used."; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category.
|
||||
/// </summary>
|
||||
/// <value>The category.</value>
|
||||
public override string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Maintenance";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -10,23 +9,24 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// <summary>
|
||||
/// Class PeopleValidationTask
|
||||
/// </summary>
|
||||
public class PeopleValidationTask : BaseScheduledTask<Kernel>
|
||||
public class PeopleValidationTask : IScheduledTask
|
||||
{
|
||||
private readonly Kernel _kernel;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PeopleValidationTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="logger"></param>
|
||||
public PeopleValidationTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
|
||||
: base(kernel, taskManager, logger)
|
||||
public PeopleValidationTask(Kernel kernel)
|
||||
{
|
||||
_kernel = kernel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[]
|
||||
{
|
||||
@@ -42,16 +42,16 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
return Kernel.LibraryManager.ValidatePeople(cancellationToken, progress);
|
||||
return _kernel.LibraryManager.ValidatePeople(cancellationToken, progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the task
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
public string Name
|
||||
{
|
||||
get { return "Refresh people"; }
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
public string Description
|
||||
{
|
||||
get { return "Updates metadata for actors, artists and directors in your media library."; }
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// Gets the category.
|
||||
/// </summary>
|
||||
/// <value>The category.</value>
|
||||
public override string Category
|
||||
public string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.ScheduledTasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin Update Task
|
||||
/// </summary>
|
||||
public class PluginUpdateTask : BaseScheduledTask<Kernel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginUpdateTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="logger"></param>
|
||||
public PluginUpdateTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
|
||||
: base(kernel, taskManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the triggers that define when the task will run
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[] {
|
||||
|
||||
// 1:30am
|
||||
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1.5) },
|
||||
|
||||
new IntervalTrigger { Interval = TimeSpan.FromHours(2)}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update installed plugins
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected override async Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
progress.Report(0);
|
||||
|
||||
var packagesToInstall = (await Kernel.InstallationManager.GetAvailablePluginUpdates(true, cancellationToken).ConfigureAwait(false)).ToList();
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
// Create tasks for each one
|
||||
var tasks = packagesToInstall.Select(i => Task.Run(async () =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
await Kernel.InstallationManager.InstallPackage(i, new Progress<double> { }, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// InstallPackage has it's own inner cancellation token, so only throw this if it's ours
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
Logger.ErrorException("Error downloading {0}", ex, i.name);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.ErrorException("Error updating {0}", ex, i.name);
|
||||
}
|
||||
|
||||
// Update progress
|
||||
lock (progress)
|
||||
{
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= packagesToInstall.Count;
|
||||
|
||||
progress.Report((90 * percent) + 10);
|
||||
}
|
||||
}));
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the task
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
{
|
||||
get { return "Check for plugin updates"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
{
|
||||
get { return "Downloads and installs updates for plugins that are configured to update automatically."; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,23 +10,27 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// <summary>
|
||||
/// Class RefreshMediaLibraryTask
|
||||
/// </summary>
|
||||
public class RefreshMediaLibraryTask : BaseScheduledTask<Kernel>
|
||||
public class RefreshMediaLibraryTask : IScheduledTask
|
||||
{
|
||||
/// <summary>
|
||||
/// The _kernel
|
||||
/// </summary>
|
||||
private readonly Kernel _kernel;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
/// <param name="logger"></param>
|
||||
public RefreshMediaLibraryTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
|
||||
: base(kernel, taskManager, logger)
|
||||
public RefreshMediaLibraryTask(Kernel kernel)
|
||||
{
|
||||
_kernel = kernel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default triggers.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
||||
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
{
|
||||
return new ITaskTrigger[] {
|
||||
|
||||
@@ -45,20 +48,20 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
progress.Report(0);
|
||||
|
||||
return Kernel.LibraryManager.ValidateMediaLibrary(progress, cancellationToken);
|
||||
return _kernel.LibraryManager.ValidateMediaLibrary(progress, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
public string Name
|
||||
{
|
||||
get { return "Scan media library"; }
|
||||
}
|
||||
@@ -67,7 +70,7 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
public string Description
|
||||
{
|
||||
get { return "Scans your media library and refreshes metatata based on configuration."; }
|
||||
}
|
||||
@@ -76,7 +79,7 @@ namespace MediaBrowser.Controller.ScheduledTasks
|
||||
/// Gets the category.
|
||||
/// </summary>
|
||||
/// <value>The category.</value>
|
||||
public override string Category
|
||||
public string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Common.Events;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Common.Progress;
|
||||
@@ -119,6 +120,12 @@ namespace MediaBrowser.Controller.Updates
|
||||
/// <value>The HTTP client.</value>
|
||||
protected IHttpClient HttpClient { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the application host.
|
||||
/// </summary>
|
||||
/// <value>The application host.</value>
|
||||
protected IApplicationHost ApplicationHost { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallationManager" /> class.
|
||||
/// </summary>
|
||||
@@ -128,8 +135,9 @@ namespace MediaBrowser.Controller.Updates
|
||||
/// <param name="networkManager">The network 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)
|
||||
public InstallationManager(Kernel kernel, IHttpClient httpClient, IZipClient zipClient, INetworkManager networkManager, IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost)
|
||||
: base(kernel)
|
||||
{
|
||||
if (zipClient == null)
|
||||
@@ -155,6 +163,7 @@ namespace MediaBrowser.Controller.Updates
|
||||
|
||||
JsonSerializer = jsonSerializer;
|
||||
HttpClient = httpClient;
|
||||
ApplicationHost = appHost;
|
||||
_networkManager = networkManager;
|
||||
_logger = logger;
|
||||
ZipClient = zipClient;
|
||||
@@ -276,7 +285,7 @@ namespace MediaBrowser.Controller.Updates
|
||||
|
||||
return package.versions
|
||||
.OrderByDescending(v => v.version)
|
||||
.FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, Kernel.ApplicationVersion));
|
||||
.FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, ApplicationHost.ApplicationVersion));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user