mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 09:04:42 +01:00
add more methods to IFileSystem
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user