Removed primitives from services in Program.cs

This will make it easier to move dependency registration
to a system without having to new up all the services first.
Moved the primitives to an IConfiguration which is much easier to inject.
This commit is contained in:
William Taylor
2019-02-08 09:13:58 +00:00
parent 25c2267a89
commit 0d5fbcb031
4 changed files with 66 additions and 35 deletions

View File

@@ -4,8 +4,10 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO
@@ -20,30 +22,30 @@ namespace Emby.Server.Implementations.IO
private readonly bool _supportsAsyncFileStreams;
private char[] _invalidFileNameChars;
private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
private bool EnableSeparateFileAndDirectoryQueries;
private readonly bool EnableSeparateFileAndDirectoryQueries;
private string _tempPath;
private readonly string _tempPath;
private IEnvironmentInfo _environmentInfo;
private bool _isEnvironmentCaseInsensitive;
private readonly IEnvironmentInfo _environmentInfo;
private readonly bool _isEnvironmentCaseInsensitive;
private string _defaultDirectory;
private readonly string _defaultDirectory;
public ManagedFileSystem(
ILoggerFactory loggerFactory,
IEnvironmentInfo environmentInfo,
string defaultDirectory,
string tempPath,
bool enableSeparateFileAndDirectoryQueries)
IApplicationPaths applicationPaths,
IConfiguration configuration)
{
Logger = loggerFactory.CreateLogger("FileSystem");
_supportsAsyncFileStreams = true;
_tempPath = tempPath;
_tempPath = applicationPaths.TempDirectory;
_environmentInfo = environmentInfo;
_defaultDirectory = defaultDirectory;
_defaultDirectory = configuration["ManagedFileSystem:DefaultDirectory"];
// On Linux with mono, this needs to be true or symbolic links are ignored
EnableSeparateFileAndDirectoryQueries = enableSeparateFileAndDirectoryQueries;
EnableSeparateFileAndDirectoryQueries =
bool.Parse(configuration["ManagedFileSystem:EnableSeparateFileAndDirectoryQueries"]);
SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
@@ -718,7 +720,7 @@ namespace Emby.Server.Implementations.IO
SetAttributes(path, false, false);
File.Delete(path);
}
public virtual List<FileSystemMetadata> GetDrives()
{
// Only include drives in the ready state or this method could end up being very slow, waiting for drives to timeout
@@ -790,7 +792,7 @@ namespace Emby.Server.Implementations.IO
{
return infos.Select(GetFileSystemMetadata);
}
public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
{
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;