add more methods to IFileSystem

pull/702/head
Luke Pulverenti 9 years ago
parent 6cb184fcf8
commit 8cf45a3e4a

@ -191,7 +191,7 @@ namespace Emby.Drawing.ImageMagick
{
var currentImageSize = new ImageSize(imageWidth, imageHeight);
new UnplayedCountIndicator(_appPaths).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
new UnplayedCountIndicator(_appPaths, _fileSystem).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
}
if (options.PercentPlayed > 0)
@ -212,15 +212,15 @@ namespace Emby.Drawing.ImageMagick
if (ratio >= 1.4)
{
new StripCollageBuilder(_appPaths).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
new StripCollageBuilder(_appPaths, _fileSystem).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
else if (ratio >= .9)
{
new StripCollageBuilder(_appPaths).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
new StripCollageBuilder(_appPaths, _fileSystem).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
else
{
new StripCollageBuilder(_appPaths).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
new StripCollageBuilder(_appPaths, _fileSystem).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
}

@ -1,5 +1,6 @@
using ImageMagickSharp;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.Drawing;
using System.Globalization;
@ -10,10 +11,12 @@ namespace Emby.Drawing.ImageMagick
private const int OffsetFromTopRightCorner = 38;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
public UnplayedCountIndicator(IApplicationPaths appPaths)
public UnplayedCountIndicator(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
_fileSystem = fileSystem;
}
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)

@ -4,6 +4,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Providers;
using ServiceStack;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Api
{
@ -37,11 +38,13 @@ namespace MediaBrowser.Api
{
private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager)
public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager, IFileSystem fileSystem)
{
_libraryManager = libraryManager;
_providerManager = providerManager;
_fileSystem = fileSystem;
}
/// <summary>

@ -27,6 +27,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Api.Library
{
@ -282,12 +283,13 @@ namespace MediaBrowser.Api.Library
private readonly IChannelManager _channelManager;
private readonly ITVSeriesManager _tvManager;
private readonly ILibraryMonitor _libraryMonitor;
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager,
IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor)
IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem)
{
_itemRepo = itemRepo;
_libraryManager = libraryManager;
@ -301,6 +303,7 @@ namespace MediaBrowser.Api.Library
_channelManager = channelManager;
_tvManager = tvManager;
_libraryMonitor = libraryMonitor;
_fileSystem = fileSystem;
}
public object Get(GetSimilarItems request)

@ -210,7 +210,10 @@ namespace MediaBrowser.Api.Library
{
var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection");
_fileSystem.CreateFile(path);
using (File.Create(path))
{
}
}
}
finally

@ -16,6 +16,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MimeTypes = MediaBrowser.Model.Net.MimeTypes;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Api.Subtitles
{
@ -127,14 +128,16 @@ namespace MediaBrowser.Api.Subtitles
private readonly ISubtitleEncoder _subtitleEncoder;
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
public SubtitleService(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProviderManager providerManager)
public SubtitleService(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProviderManager providerManager, IFileSystem fileSystem)
{
_libraryManager = libraryManager;
_subtitleManager = subtitleManager;
_subtitleEncoder = subtitleEncoder;
_mediaSourceManager = mediaSourceManager;
_providerManager = providerManager;
_fileSystem = fileSystem;
}
public async Task<object> Get(GetSubtitlePlaylist request)

@ -321,7 +321,7 @@ namespace MediaBrowser.Common.Implementations
protected virtual IJsonSerializer CreateJsonSerializer()
{
return new JsonSerializer();
return new JsonSerializer(FileSystemManager);
}
private void SetHttpLimit()
@ -450,7 +450,7 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger, FileSystemManager);
RegisterSingleInstance(JsonSerializer);
RegisterSingleInstance(XmlSerializer);
@ -651,7 +651,7 @@ namespace MediaBrowser.Common.Implementations
{
try
{
return Assembly.Load(FileSystemManager.ReadAllBytes((file)));
return Assembly.Load(File.ReadAllBytes((file)));
}
catch (Exception ex)
{

@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations
{
_dataDirectory = Path.Combine(ProgramDataPath, "data");
FileSystem.CreateDirectory(_dataDirectory);
Directory.CreateDirectory(_dataDirectory);
}
return _dataDirectory;
@ -152,7 +152,7 @@ namespace MediaBrowser.Common.Implementations
{
_cachePath = Path.Combine(ProgramDataPath, "cache");
FileSystem.CreateDirectory(_cachePath);
Directory.CreateDirectory(_cachePath);
}
return _cachePath;

@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
{
var path = CommonApplicationPaths.SystemConfigurationFilePath;
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
Directory.CreateDirectory(Path.GetDirectoryName(path));
lock (_configurationSyncLock)
{
@ -276,7 +276,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
var path = GetConfigurationFile(key);
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
Directory.CreateDirectory(Path.GetDirectoryName(path));
lock (_configurationSyncLock)
{

@ -19,7 +19,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
/// <param name="path">The path.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
/// <returns>System.Object.</returns>
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer, IFileSystem fileSystem)
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer)
{
object configuration;
@ -28,7 +28,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
// Use try/catch to avoid the extra file system lookup using File.Exists
try
{
buffer = fileSystem.ReadAllBytes(path);
buffer = File.ReadAllBytes(path);
configuration = xmlSerializer.DeserializeFromBytes(type, buffer);
}
@ -47,10 +47,10 @@ namespace MediaBrowser.Common.Implementations.Configuration
// If the file didn't exist before, or if something has changed, re-save
if (buffer == null || !buffer.SequenceEqual(newBytes))
{
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
Directory.CreateDirectory(Path.GetDirectoryName(path));
// Save it after load in case we got new items
fileSystem.WriteAllBytes(path, newBytes);
File.WriteAllBytes(path, newBytes);
}
return configuration;

@ -26,7 +26,7 @@ namespace MediaBrowser.Common.Implementations.Devices
{
lock (_syncLock)
{
var value = _fileSystem.ReadAllText(CachePath, Encoding.UTF8);
var value = File.ReadAllText(CachePath, Encoding.UTF8);
Guid guid;
if (Guid.TryParse(value, out guid))

@ -107,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO
throw new ArgumentNullException("target");
}
_fileSystem.WriteAllText(shortcutPath, target);
File.WriteAllText(shortcutPath, target);
}
/// <summary>
@ -449,5 +449,55 @@ namespace MediaBrowser.Common.Implementations.IO
return directoryInfo.EnumerateDirectories("*", searchOption)
.Concat<FileSystemInfo>(directoryInfo.EnumerateFiles("*", searchOption));
}
public Stream OpenRead(string path)
{
return File.OpenRead(path);
}
public void CopyFile(string source, string target, bool overwrite)
{
File.Copy(source, target, overwrite);
}
public void MoveFile(string source, string target)
{
File.Move(source, target);
}
public void MoveDirectory(string source, string target)
{
Directory.Move(source, target);
}
public bool DirectoryExists(string path)
{
return Directory.Exists(path);
}
public bool FileExists(string path)
{
return File.Exists(path);
}
public string ReadAllText(string path)
{
return File.ReadAllText(path);
}
public void WriteAllText(string path, string text, Encoding encoding)
{
File.WriteAllText(path, text, encoding);
}
public void WriteAllText(string path, string text)
{
File.WriteAllText(path, text);
}
public string ReadAllText(string path, Encoding encoding)
{
return File.ReadAllText(path, encoding);
}
}
}

@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Logging
{
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt");
_fileSystem.CreateDirectory(Path.GetDirectoryName(LogFilePath));
Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath));
AddFileTarget(LogFilePath, level);

@ -12,6 +12,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Common.Implementations.ScheduledTasks
{
@ -51,6 +52,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// </summary>
/// <value>The task manager.</value>
private ITaskManager TaskManager { get; set; }
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class.
@ -71,7 +73,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// or
/// logger
/// </exception>
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger)
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem)
{
if (scheduledTask == null)
{
@ -99,6 +101,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
TaskManager = taskManager;
JsonSerializer = jsonSerializer;
Logger = logger;
_fileSystem = fileSystem;
ReloadTriggerEvents(true);
}

@ -10,6 +10,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Common.Implementations.ScheduledTasks
{
@ -50,6 +51,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// </summary>
/// <value>The logger.</value>
private ILogger Logger { get; set; }
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="TaskManager" /> class.
@ -58,11 +60,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentException">kernel</exception>
public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger)
public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem)
{
ApplicationPaths = applicationPaths;
JsonSerializer = jsonSerializer;
Logger = logger;
_fileSystem = fileSystem;
ScheduledTasks = new IScheduledTaskWorker[] { };
}
@ -175,7 +178,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
var myTasks = ScheduledTasks.ToList();
var list = tasks.ToList();
myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger)));
myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem)));
ScheduledTasks = myTasks.ToArray();
}

@ -99,15 +99,15 @@ namespace MediaBrowser.Common.Implementations.Security
{
try
{
contents = _fileSystem.ReadAllLines(licenseFile);
contents = File.ReadAllLines(licenseFile);
}
catch (DirectoryNotFoundException)
{
(_fileSystem.CreateFile(licenseFile)).Close();
(File.Create(licenseFile)).Close();
}
catch (FileNotFoundException)
{
(_fileSystem.CreateFile(licenseFile)).Close();
(File.Create(licenseFile)).Close();
}
}
if (contents != null && contents.Length > 0)
@ -150,8 +150,8 @@ namespace MediaBrowser.Common.Implementations.Security
}
var licenseFile = Filename;
_fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile));
lock (_fileLock) _fileSystem.WriteAllLines(licenseFile, lines);
Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
lock (_fileLock) File.WriteAllLines(licenseFile, lines);
}
}
}

@ -1,6 +1,7 @@
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Common.Implementations.Serialization
{
@ -9,8 +10,11 @@ namespace MediaBrowser.Common.Implementations.Serialization
/// </summary>
public class JsonSerializer : IJsonSerializer
{
public JsonSerializer()
private readonly IFileSystem _fileSystem;
public JsonSerializer(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
Configure();
}

@ -573,7 +573,7 @@ namespace MediaBrowser.Common.Implementations.Updates
//If it is an archive - write out a version file so we know what it is
if (isArchive)
{
_fileSystem.WriteAllText(target + ".ver", package.versionStr);
File.WriteAllText(target + ".ver", package.versionStr);
}
}
catch (IOException e)

@ -150,8 +150,8 @@ namespace MediaBrowser.Common.IO
/// <param name="path">The path.</param>
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
void DeleteDirectory(string path, bool recursive);
IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false);
IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false);
IEnumerable<FileInfo> GetFiles(string path, bool recursive = false);
@ -169,22 +169,12 @@ namespace MediaBrowser.Common.IO
bool FileExists(string path);
string ReadAllText(string path, Encoding encoding);
string ReadAllText(string path);
byte[] ReadAllBytes(string path);
void WriteAllBytes(string path, byte[] bytes);
void WriteAllText(string path, string text, Encoding encoding);
void WriteAllText(string path, string text);
void CreateFile(string path);
void WriteAllLines(string path, string[] lines);
void WriteAllText(string path, string text);
void WriteAllText(string path, string text, Encoding encoding);
string[] ReadAllLines(string path);
string ReadAllText(string path, Encoding encoding);
}
}

@ -53,5 +53,10 @@ namespace MediaBrowser.Controller.Net
/// Inits this instance.
/// </summary>
void Init(IEnumerable<IRestfulService> services);
/// <summary>
/// If set, all requests will respond with this message
/// </summary>
string GlobalResponse { get; set; }
}
}

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -21,11 +22,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public BoxSetXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public BoxSetXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -62,7 +65,7 @@ namespace MediaBrowser.LocalMetadata.Savers
var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config, _fileSystem);
}
/// <summary>

@ -9,6 +9,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -19,12 +20,14 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private IFileSystem _fileSystem;
public EpisodeXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager)
public EpisodeXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_itemRepository = itemRepository;
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -143,7 +146,8 @@ namespace MediaBrowser.LocalMetadata.Savers
"DVD_episodenumber",
"DVD_season",
"absolute_number"
}, _config);
}, _config, _fileSystem);
}
/// <summary>

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -24,11 +25,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public FolderXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public FolderXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -76,7 +79,7 @@ namespace MediaBrowser.LocalMetadata.Savers
var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config, _fileSystem);
}
/// <summary>

@ -6,6 +6,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -21,11 +22,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public GameSystemXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public GameSystemXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -69,7 +72,7 @@ namespace MediaBrowser.LocalMetadata.Savers
var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { }, _config, _fileSystem);
}
/// <summary>

@ -8,6 +8,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -26,11 +27,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public GameXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public GameXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -101,7 +104,7 @@ namespace MediaBrowser.LocalMetadata.Savers
"GameSystem",
"NesBox",
"NesBoxRom"
}, _config);
}, _config, _fileSystem);
}
public string GetSavePath(IHasMetadata item)

@ -9,6 +9,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -20,12 +21,14 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IItemRepository _itemRepository;
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private IFileSystem _fileSystem;
public MovieXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager)
public MovieXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_itemRepository = itemRepository;
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
public string Name
@ -122,7 +125,7 @@ namespace MediaBrowser.LocalMetadata.Savers
"Artist",
"Album",
"TmdbCollectionName"
}, _config);
}, _config, _fileSystem);
}
public string GetSavePath(IHasMetadata item)

@ -6,6 +6,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -24,11 +25,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public PersonXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public PersonXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -75,7 +78,7 @@ namespace MediaBrowser.LocalMetadata.Savers
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
{
"PlaceOfBirth"
}, _config);
}, _config, _fileSystem);
}
/// <summary>

@ -7,6 +7,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -22,11 +23,13 @@ namespace MediaBrowser.LocalMetadata.Savers
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public PlaylistXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager)
public PlaylistXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
/// <summary>
@ -75,7 +78,7 @@ namespace MediaBrowser.LocalMetadata.Savers
"OwnerUserId",
"PlaylistMediaType"
}, _config);
}, _config, _fileSystem);
}
/// <summary>

@ -9,6 +9,7 @@ using System.IO;
using System.Security;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.LocalMetadata.Savers
{
@ -16,11 +17,13 @@ namespace MediaBrowser.LocalMetadata.Savers
{
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private IFileSystem _fileSystem;
public SeriesXmlProvider(IServerConfigurationManager config, ILibraryManager libraryManager)
public SeriesXmlProvider(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
public string Name
@ -134,7 +137,7 @@ namespace MediaBrowser.LocalMetadata.Savers
// Deprecated. No longer saving in this field.
"AnimeSeriesIndex"
}, _config);
}, _config, _fileSystem);
}
/// <summary>

@ -2,26 +2,37 @@
using MediaBrowser.Model.Configuration;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Common.IO;
namespace MediaBrowser.MediaEncoding.Configuration
{
public class EncodingConfigurationFactory : IConfigurationFactory
{
private readonly IFileSystem _fileSystem;
public EncodingConfigurationFactory(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
public IEnumerable<ConfigurationStore> GetConfigurations()
{
return new[]
{
new EncodingConfigurationStore()
new EncodingConfigurationStore(_fileSystem)
};
}
}
public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
{
public EncodingConfigurationStore()
private readonly IFileSystem _fileSystem;
public EncodingConfigurationStore(IFileSystem fileSystem)
{
ConfigurationType = typeof(EncodingOptions);
Key = "encoding";
_fileSystem = fileSystem;
}
public void Validate(object oldConfig, object newConfig)
@ -35,7 +46,7 @@ namespace MediaBrowser.MediaEncoding.Configuration
&& !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath))
{
// Validate
if (!_fileSystem.DirectoryExists(newPath))
if (!_fileSystem.DirectoryExists(newPath))
{
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
}

@ -1184,15 +1184,6 @@
<Compile Include="..\MediaBrowser.Model\Tasks\TaskTriggerInfo.cs">
<Link>Tasks\TaskTriggerInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\AppTheme.cs">
<Link>Themes\AppTheme.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\AppThemeInfo.cs">
<Link>Themes\AppThemeInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\ThemeImage.cs">
<Link>Themes\ThemeImage.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Updates\CheckForUpdateResult.cs">
<Link>Updates\CheckForUpdateResult.cs</Link>
</Compile>

@ -1140,15 +1140,6 @@
<Compile Include="..\MediaBrowser.Model\Tasks\TaskTriggerInfo.cs">
<Link>Tasks\TaskTriggerInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\AppTheme.cs">
<Link>Themes\AppTheme.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\AppThemeInfo.cs">
<Link>Themes\AppThemeInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Themes\ThemeImage.cs">
<Link>Themes\ThemeImage.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Updates\CheckForUpdateResult.cs">
<Link>Updates\CheckForUpdateResult.cs</Link>
</Compile>

@ -10,6 +10,7 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Providers.TV
{
@ -19,15 +20,17 @@ namespace MediaBrowser.Providers.TV
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager)
public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IFileSystem fileSystem)
{
_config = config;
_logger = logger;
_localization = localization;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
}
public async Task Run(Series series, CancellationToken cancellationToken)

@ -15,6 +15,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Providers.TV
{
@ -24,15 +25,17 @@ namespace MediaBrowser.Providers.TV
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
private readonly IFileSystem _fileSystem;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public MissingEpisodeProvider(ILogger logger, IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization)
public MissingEpisodeProvider(ILogger logger, IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization, IFileSystem fileSystem)
{
_logger = logger;
_config = config;
_libraryManager = libraryManager;
_localization = localization;
_fileSystem = fileSystem;
}
public async Task Run(IEnumerable<IGrouping<string, Series>> series, CancellationToken cancellationToken)
@ -395,7 +398,7 @@ namespace MediaBrowser.Providers.TV
if (season == null)
{
var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager);
var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager, _fileSystem);
season = await provider.AddSeason(series, seasonNumber, cancellationToken).ConfigureAwait(false);
}

@ -29,7 +29,7 @@ namespace MediaBrowser.Providers.TV
if (refreshOptions.IsPostRecursiveRefresh)
{
var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager);
var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager, FileSystem);
try
{

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Providers.TV
{
@ -27,13 +28,15 @@ namespace MediaBrowser.Providers.TV
private readonly IServerConfigurationManager _config;
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
private readonly IFileSystem _fileSystem;
public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, ILocalizationManager localization)
public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, ILocalizationManager localization, IFileSystem fileSystem)
{
_libraryManager = libraryManager;
_logger = logger;
_config = config;
_localization = localization;
_fileSystem = fileSystem;
}
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
@ -50,7 +53,7 @@ namespace MediaBrowser.Providers.TV
var seriesGroups = FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList();
await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization).Run(seriesGroups, cancellationToken).ConfigureAwait(false);
await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem).Run(seriesGroups, cancellationToken).ConfigureAwait(false);
var numComplete = 0;

@ -448,7 +448,7 @@ namespace MediaBrowser.Server.Implementations.Channels
item.Name = channelInfo.Name;
}
await item.RefreshMetadata(new MetadataRefreshOptions
await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
{
ForceSave = isNew

@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Collections
await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService()), CancellationToken.None)
await collection.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), CancellationToken.None)
.ConfigureAwait(false);
if (options.ItemIdList.Count > 0)

@ -1,16 +1,19 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using System.IO;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Collections
{
public class CollectionsDynamicFolder : IVirtualFolderCreator
{
private readonly IApplicationPaths _appPaths;
private IFileSystem _fileSystem;
public CollectionsDynamicFolder(IApplicationPaths appPaths)
public CollectionsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
_fileSystem = fileSystem;
}
public BasePluginFolder GetFolder()

@ -15,6 +15,7 @@ using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Linq;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Configuration
{
@ -23,15 +24,18 @@ namespace MediaBrowser.Server.Implementations.Configuration
/// </summary>
public class ServerConfigurationManager : BaseConfigurationManager, IServerConfigurationManager
{
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="ServerConfigurationManager" /> class.
/// </summary>
/// <param name="applicationPaths">The application paths.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer)
public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem)
: base(applicationPaths, logManager, xmlSerializer)
{
_fileSystem = fileSystem;
UpdateItemsByNamePath();
UpdateMetadataPath();
}

@ -10,6 +10,7 @@ using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Connect
{
@ -23,8 +24,9 @@ namespace MediaBrowser.Server.Implementations.Connect
private readonly INetworkManager _networkManager;
private readonly IApplicationHost _appHost;
private readonly IFileSystem _fileSystem;
public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost)
public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem)
{
_httpClient = httpClient;
_appPaths = appPaths;
@ -32,6 +34,7 @@ namespace MediaBrowser.Server.Implementations.Connect
_networkManager = networkManager;
_connectManager = connectManager;
_appHost = appHost;
_fileSystem = fileSystem;
}
public void Run()

@ -23,6 +23,7 @@ using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Connect
{
@ -40,6 +41,7 @@ namespace MediaBrowser.Server.Implementations.Connect
private readonly IUserManager _userManager;
private readonly IProviderManager _providerManager;
private readonly ISecurityManager _securityManager;
private readonly IFileSystem _fileSystem;
private ConnectData _data = new ConnectData();
@ -104,7 +106,7 @@ namespace MediaBrowser.Server.Implementations.Connect
IEncryptionManager encryption,
IHttpClient httpClient,
IServerApplicationHost appHost,
IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager, ISecurityManager securityManager)
IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager, ISecurityManager securityManager, IFileSystem fileSystem)
{
_logger = logger;
_appPaths = appPaths;
@ -116,6 +118,7 @@ namespace MediaBrowser.Server.Implementations.Connect
_userManager = userManager;
_providerManager = providerManager;
_securityManager = securityManager;
_fileSystem = fileSystem;
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
@ -943,7 +946,7 @@ namespace MediaBrowser.Server.Implementations.Connect
{
await _providerManager.SaveImage(user, imageUrl, _connectImageSemaphore, ImageType.Primary, null, CancellationToken.None).ConfigureAwait(false);
await user.RefreshMetadata(new MetadataRefreshOptions
await user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
{
ForceSave = true,

@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
using System;
using System.IO;
using System.Linq;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Devices
{
@ -51,10 +52,12 @@ namespace MediaBrowser.Server.Implementations.Devices
public class CameraUploadsDynamicFolder : IVirtualFolderCreator
{
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
public CameraUploadsDynamicFolder(IApplicationPaths appPaths)
public CameraUploadsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
_fileSystem = fileSystem;
}
public BasePluginFolder GetFolder()

@ -187,7 +187,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
try
{
_logger.Debug("Deleting empty directory {0}", path);
_fileSystem.DeleteDirectory(path);
_fileSystem.DeleteDirectory(path, false);
}
catch (UnauthorizedAccessException) { }
catch (DirectoryNotFoundException) { }

@ -79,6 +79,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
_containerAdapter = new ContainerAdapter(applicationHost);
}
public string GlobalResponse { get; set; }
public override void Configure(Container container)
{
HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath;
@ -336,6 +338,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
return Task.FromResult(true);
}
if (!string.IsNullOrWhiteSpace(GlobalResponse))
{
httpRes.Write(GlobalResponse);
httpRes.ContentType = "text/plain";
return Task.FromResult(true);
}
var handler = HttpHandlerFactory.GetHandler(httpReq);
var remoteIp = httpReq.RemoteIp;

@ -548,7 +548,7 @@ namespace MediaBrowser.Server.Implementations.Library
public BaseItem ResolvePath(FileSystemInfo fileInfo,
Folder parent = null)
{
return ResolvePath(fileInfo, new DirectoryService(_logger), parent);
return ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), parent);
}
private BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null)
@ -1009,7 +1009,7 @@ namespace MediaBrowser.Server.Implementations.Library
// Ensure the location is available.
_fileSystem.CreateDirectory(ConfigurationManager.ApplicationPaths.PeoplePath);
return new PeopleValidator(this, _logger, ConfigurationManager).ValidatePeople(cancellationToken, progress);
return new PeopleValidator(this, _logger, ConfigurationManager, _fileSystem).ValidatePeople(cancellationToken, progress);
}
/// <summary>
@ -1064,7 +1064,7 @@ namespace MediaBrowser.Server.Implementations.Library
progress.Report(.5);
// Start by just validating the children of the root, but go no further
await RootFolder.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(), recursive: false);
await RootFolder.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false);
progress.Report(1);
@ -1072,7 +1072,7 @@ namespace MediaBrowser.Server.Implementations.Library
await userRoot.RefreshMetadata(cancellationToken).ConfigureAwait(false);
await userRoot.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(), recursive: false).ConfigureAwait(false);
await userRoot.ValidateChildren(new Progress<double>(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false);
progress.Report(2);
var innerProgress = new ActionableProgress<double>();
@ -1080,7 +1080,7 @@ namespace MediaBrowser.Server.Implementations.Library
innerProgress.RegisterAction(pct => progress.Report(2 + pct * .73));
// Now validate the entire media library
await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(), recursive: true).ConfigureAwait(false);
await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: true).ConfigureAwait(false);
progress.Report(75);
@ -1702,7 +1702,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (refresh)
{
await item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None).ConfigureAwait(false);
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
{
// Not sure why this is necessary but need to figure it out
// View images are not getting utilized without this
@ -1790,7 +1790,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (refresh)
{
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
{
// Need to force save to increment DateLastSaved
ForceSave = true
@ -1860,7 +1860,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (refresh)
{
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
{
// Need to force save to increment DateLastSaved
ForceSave = true

@ -15,6 +15,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Library
{
@ -24,17 +25,19 @@ namespace MediaBrowser.Server.Implementations.Library
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem;
private IMediaSourceProvider[] _providers;
private readonly ILogger _logger;
public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer)
public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem)
{
_itemRepo = itemRepo;
_userManager = userManager;
_libraryManager = libraryManager;
_logger = logger;
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
}
public void AddParts(IEnumerable<IMediaSourceProvider> providers)

@ -454,7 +454,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>Task.</returns>
public Task RefreshUsersMetadata(CancellationToken cancellationToken)
{
var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken)).ToList();
var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken)).ToList();
return Task.WhenAll(tasks);
}

@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Library.Validators
{
@ -29,17 +30,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="PeopleValidator" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
/// <param name="logger">The logger.</param>
public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config)
public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
{
_libraryManager = libraryManager;
_logger = logger;
_config = config;
_fileSystem = fileSystem;
}
private bool DownloadMetadata(PersonInfo i, PeopleMetadataOptions options)
@ -121,7 +124,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
validIds.Add(item.Id);
var options = new MetadataRefreshOptions
var options = new MetadataRefreshOptions(_fileSystem)
{
MetadataRefreshMode = person.Value ? MetadataRefreshMode.Default : MetadataRefreshMode.ValidationOnly,
ImageRefreshMode = person.Value ? ImageRefreshMode.Default : ImageRefreshMode.ValidationOnly

@ -71,9 +71,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
_liveTvManager = (LiveTvManager)liveTvManager;
_jsonSerializer = jsonSerializer;
_recordingProvider = new ItemDataProvider<RecordingInfo>(jsonSerializer, _logger, Path.Combine(DataPath, "recordings"), (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase));
_seriesTimerProvider = new SeriesTimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers"));
_timerProvider = new TimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "timers"));
_recordingProvider = new ItemDataProvider<RecordingInfo>(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "recordings"), (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase));
_seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers"));
_timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"));
_timerProvider.TimerFired += _timerProvider_TimerFired;
}
@ -239,7 +239,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
try
{
_filesystem.DeleteFile(remove.Path);
_fileSystem.DeleteFile(remove.Path);
}
catch (DirectoryNotFoundException)
{

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
@ -16,13 +17,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
protected readonly ILogger Logger;
private readonly string _dataPath;
protected readonly Func<T, T, bool> EqualityComparer;
private readonly IFileSystem _fileSystem;
public ItemDataProvider(IJsonSerializer jsonSerializer, ILogger logger, string dataPath, Func<T, T, bool> equalityComparer)
public ItemDataProvider(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, Func<T, T, bool> equalityComparer)
{
Logger = logger;
_dataPath = dataPath;
EqualityComparer = equalityComparer;
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
}
public IReadOnlyList<T> GetAll()

@ -2,13 +2,14 @@
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
public class SeriesTimerManager : ItemDataProvider<SeriesTimerInfo>
{
public SeriesTimerManager(IJsonSerializer jsonSerializer, ILogger logger, string dataPath)
: base(jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
public SeriesTimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath)
: base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
{
}

@ -7,6 +7,7 @@ using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
@ -16,8 +17,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
public event EventHandler<GenericEventArgs<TimerInfo>> TimerFired;
public TimerManager(IJsonSerializer jsonSerializer, ILogger logger, string dataPath)
: base(jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath)
: base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase))
{
}

@ -580,7 +580,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
item.Name = channelInfo.Name;
}
await item.RefreshMetadata(new MetadataRefreshOptions
await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
{
ForceSave = isNew,
ReplaceImages = replaceImages.Distinct().ToList()
@ -659,7 +659,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions());
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem));
return item;
}
@ -759,7 +759,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
}
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions());
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem));
return item.Id;
}

@ -12,14 +12,18 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
{
public class M3UTunerHost : BaseTunerHost, ITunerHost
{
public M3UTunerHost(IConfigurationManager config, ILogger logger)
private readonly IFileSystem _fileSystem;
public M3UTunerHost(IConfigurationManager config, ILogger logger, IFileSystem fileSystem)
: base(config, logger)
{
_fileSystem = fileSystem;
}
public override string Type

@ -173,5 +173,6 @@
"HeaderProducer": "Producers",
"HeaderWriter": "Writers",
"HeaderParentalRatings": "Parental Ratings",
"HeaderCommunityRatings": "Community ratings"
"HeaderCommunityRatings": "Community ratings",
"StartupEmbyServerIsLoading": "Emby Server is loading. Please try again shortly."
}

@ -212,7 +212,7 @@ namespace MediaBrowser.Server.Implementations.Localization
/// <returns>Dictionary{System.StringParentalRating}.</returns>
private void LoadRatings(string file)
{
var dict = _fileSystem.ReadAllLines(file).Select(i =>
var dict = File.ReadAllLines(file).Select(i =>
{
if (!string.IsNullOrWhiteSpace(i))
{

@ -617,7 +617,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// <returns>Task.</returns>
public Task SaveCriticReviews(Guid itemId, IEnumerable<ItemReview> criticReviews)
{
_fileSystem.CreateDirectory(_criticReviewsPath);
Directory.CreateDirectory(_criticReviewsPath);
var path = Path.Combine(_criticReviewsPath, itemId + ".json");

@ -4,6 +4,7 @@ using MediaBrowser.Controller.Playlists;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.Playlists
{
@ -46,10 +47,12 @@ namespace MediaBrowser.Server.Implementations.Playlists
public class PlaylistsDynamicFolder : IVirtualFolderCreator
{
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
public PlaylistsDynamicFolder(IApplicationPaths appPaths)
public PlaylistsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
_fileSystem = fileSystem;
}
public BasePluginFolder GetFolder()

@ -128,7 +128,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
await parentFolder.AddChild(playlist, CancellationToken.None).ConfigureAwait(false);
await playlist.RefreshMetadata(new MetadataRefreshOptions { ForceSave = true }, CancellationToken.None)
await playlist.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = true }, CancellationToken.None)
.ConfigureAwait(false);
if (options.ItemIdList.Count > 0)
@ -196,7 +196,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
await playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(_fileSystem)
{
ForceSave = true
});
@ -223,7 +223,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
await playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(_fileSystem)
{
ForceSave = true
});

@ -11,6 +11,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
@ -39,6 +40,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
private readonly IApplicationPaths _appPaths;
private readonly IEncodingManager _encodingManager;
private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="ChapterImagesTask" /> class.
@ -46,13 +48,14 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <param name="logManager">The log manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="itemRepo">The item repo.</param>
public ChapterImagesTask(ILogManager logManager, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager)
public ChapterImagesTask(ILogManager logManager, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager, IFileSystem fileSystem)
{
_logger = logManager.GetLogger(GetType().Name);
_libraryManager = libraryManager;
_itemRepo = itemRepo;
_appPaths = appPaths;
_encodingManager = encodingManager;
_fileSystem = fileSystem;
}
/// <summary>

@ -42,7 +42,6 @@ using MediaBrowser.Controller.Social;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Controller.Themes;
using MediaBrowser.Controller.TV;
using MediaBrowser.Dlna;
using MediaBrowser.Dlna.ConnectionManager;
@ -87,7 +86,6 @@ using MediaBrowser.Server.Implementations.ServerManager;
using MediaBrowser.Server.Implementations.Session;
using MediaBrowser.Server.Implementations.Social;
using MediaBrowser.Server.Implementations.Sync;
using MediaBrowser.Server.Implementations.Themes;
using MediaBrowser.Server.Implementations.TV;
using MediaBrowser.Server.Startup.Common.FFMpeg;
using MediaBrowser.Server.Startup.Common.Migrations;
@ -124,7 +122,7 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>IConfigurationManager.</returns>
protected override IConfigurationManager GetConfigurationManager()
{
return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer, FileSystemManager);
}
/// <summary>
@ -314,6 +312,7 @@ namespace MediaBrowser.Server.Startup.Common
await base.RunStartupTasks().ConfigureAwait(false);
Logger.Info("Core startup complete");
HttpServer.GlobalResponse = null;
Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
{
@ -434,6 +433,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, "Emby", "web/index.html");
HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
RegisterSingleInstance(HttpServer, false);
progress.Report(10);
@ -458,7 +458,7 @@ namespace MediaBrowser.Server.Startup.Common
var encryptionManager = new EncryptionManager();
RegisterSingleInstance<IEncryptionManager>(encryptionManager);
ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager);
ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager, FileSystemManager);
RegisterSingleInstance(ConnectManager);
DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, LogManager.GetLogger("DeviceManager"), FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ConfigurationManager, LogManager.GetLogger("DeviceManager"), NetworkManager);
@ -475,15 +475,12 @@ namespace MediaBrowser.Server.Startup.Common
ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LogManager.GetLogger("ChannelManager"), ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient);
RegisterSingleInstance(ChannelManager);
MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer);
MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager);
RegisterSingleInstance(MediaSourceManager);
SessionManager = new SessionManager(UserDataManager, LogManager.GetLogger("SessionManager"), UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager);
RegisterSingleInstance(SessionManager);
var appThemeManager = new AppThemeManager(ApplicationPaths, FileSystemManager, JsonSerializer, Logger);
RegisterSingleInstance<IAppThemeManager>(appThemeManager);
var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LogManager.GetLogger("Dlna"), JsonSerializer, this);
RegisterSingleInstance<IDlnaManager>(dlnaManager);
@ -573,7 +570,7 @@ namespace MediaBrowser.Server.Startup.Common
{
try
{
return new ImageMagickEncoder(LogManager.GetLogger("ImageMagick"), ApplicationPaths, HttpClient);
return new ImageMagickEncoder(LogManager.GetLogger("ImageMagick"), ApplicationPaths, HttpClient, FileSystemManager);
}
catch (Exception ex)
{
@ -598,7 +595,7 @@ namespace MediaBrowser.Server.Startup.Common
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment)
.GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false);
new FFmpegValidator(Logger, ApplicationPaths).Validate(info);
new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(info);
MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"),
JsonSerializer,

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using MediaBrowser.Common.IO;
namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
@ -13,11 +14,13 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
public FFmpegValidator(ILogger logger, IApplicationPaths appPaths)
public FFmpegValidator(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem)
{
_logger = logger;
_appPaths = appPaths;
_fileSystem = fileSystem;
}
public void Validate(FFMpegInfo info)

@ -25,7 +25,7 @@ namespace MediaBrowser.Server.Startup.Common
_logManager.Flush();
var path = Path.Combine(_appPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt");
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
Directory.CreateDirectory(Path.GetDirectoryName(path));
var builder = LogHelper.GetLogMessage(ex);
@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Startup.Common
Console.WriteLine("UnhandledException");
Console.WriteLine(builder.ToString());
_fileSystem.WriteAllText(path, builder.ToString());
File.WriteAllText(path, builder.ToString());
}
}
}

Loading…
Cancel
Save