mirror of https://github.com/jellyfin/jellyfin.git
update file system methods
This commit is contained in:
parent
0f743205c4
commit
14de062681
|
@ -46,7 +46,7 @@ namespace Emby.Drawing.Common
|
||||||
/// <exception cref="ArgumentException">The image was of an unrecognised format.</exception>
|
/// <exception cref="ArgumentException">The image was of an unrecognised format.</exception>
|
||||||
public static ImageSize GetDimensions(string path, ILogger logger, IFileSystem fileSystem)
|
public static ImageSize GetDimensions(string path, ILogger logger, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
using (var fs = File.OpenRead(path))
|
using (var fs = fileSystem.OpenRead(path))
|
||||||
{
|
{
|
||||||
using (var binaryReader = new BinaryReader(fs))
|
using (var binaryReader = new BinaryReader(fs))
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace Emby.Drawing.GDI
|
||||||
{
|
{
|
||||||
using (var croppedImage = image.CropWhitespace())
|
using (var croppedImage = image.CropWhitespace())
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
|
|
||||||
using (var outputStream = _fileSystem.GetFileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
|
using (var outputStream = _fileSystem.GetFileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,7 @@ namespace Emby.Drawing.GDI
|
||||||
|
|
||||||
var outputFormat = GetOutputFormat(originalImage, selectedOutputFormat);
|
var outputFormat = GetOutputFormat(originalImage, selectedOutputFormat);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
||||||
|
|
||||||
// Save to the cache location
|
// Save to the cache location
|
||||||
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
|
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
|
||||||
|
|
|
@ -8,6 +8,7 @@ using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace Emby.Drawing.ImageMagick
|
namespace Emby.Drawing.ImageMagick
|
||||||
{
|
{
|
||||||
|
@ -15,13 +16,15 @@ namespace Emby.Drawing.ImageMagick
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public ImageMagickEncoder(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient)
|
public ImageMagickEncoder(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
|
||||||
LogImageMagickVersion();
|
LogImageMagickVersion();
|
||||||
}
|
}
|
||||||
|
@ -77,7 +80,7 @@ namespace Emby.Drawing.ImageMagick
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
|
var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
|
||||||
|
|
||||||
using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
|
using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
|
||||||
{
|
{
|
||||||
|
@ -181,7 +184,7 @@ namespace Emby.Drawing.ImageMagick
|
||||||
{
|
{
|
||||||
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
var currentImageSize = new ImageSize(imageWidth, imageHeight);
|
||||||
|
|
||||||
var task = new PlayedIndicatorDrawer(_appPaths, _httpClient).DrawPlayedIndicator(wand, currentImageSize);
|
var task = new PlayedIndicatorDrawer(_appPaths, _httpClient, _fileSystem).DrawPlayedIndicator(wand, currentImageSize);
|
||||||
Task.WaitAll(task);
|
Task.WaitAll(task);
|
||||||
}
|
}
|
||||||
else if (options.UnplayedCount.HasValue)
|
else if (options.UnplayedCount.HasValue)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using MediaBrowser.Model.Drawing;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace Emby.Drawing.ImageMagick
|
namespace Emby.Drawing.ImageMagick
|
||||||
{
|
{
|
||||||
|
@ -14,12 +15,14 @@ namespace Emby.Drawing.ImageMagick
|
||||||
private const int OffsetFromTopRightCorner = 38;
|
private const int OffsetFromTopRightCorner = 38;
|
||||||
|
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IHttpClient _iHttpClient;
|
private readonly IHttpClient _iHttpClient;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient)
|
public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_iHttpClient = iHttpClient;
|
_iHttpClient = iHttpClient;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
|
public async Task DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
|
||||||
|
@ -38,7 +41,7 @@ namespace Emby.Drawing.ImageMagick
|
||||||
pixel.Opacity = 0;
|
pixel.Opacity = 0;
|
||||||
pixel.Color = "white";
|
pixel.Color = "white";
|
||||||
draw.FillColor = pixel;
|
draw.FillColor = pixel;
|
||||||
draw.Font = await DownloadFont("webdings.ttf", "https://github.com/MediaBrowser/Emby.Resources/raw/master/fonts/webdings.ttf", _appPaths, _iHttpClient).ConfigureAwait(false);
|
draw.Font = await DownloadFont("webdings.ttf", "https://github.com/MediaBrowser/Emby.Resources/raw/master/fonts/webdings.ttf", _appPaths, _iHttpClient, _fileSystem).ConfigureAwait(false);
|
||||||
draw.FontSize = FontSize;
|
draw.FontSize = FontSize;
|
||||||
draw.FontStyle = FontStyleType.NormalStyle;
|
draw.FontStyle = FontStyleType.NormalStyle;
|
||||||
draw.TextAlignment = TextAlignType.CenterAlign;
|
draw.TextAlignment = TextAlignType.CenterAlign;
|
||||||
|
@ -52,18 +55,18 @@ namespace Emby.Drawing.ImageMagick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ExtractFont(string name, IApplicationPaths paths)
|
internal static string ExtractFont(string name, IApplicationPaths paths, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
|
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
if (fileSystem.FileExists(filePath))
|
||||||
{
|
{
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
|
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
|
||||||
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
|
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
|
||||||
|
|
||||||
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
|
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
|
||||||
{
|
{
|
||||||
|
@ -73,11 +76,11 @@ namespace Emby.Drawing.ImageMagick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Copy(tempPath, filePath, false);
|
fileSystem.CopyFile(tempPath, filePath, false);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
@ -87,11 +90,11 @@ namespace Emby.Drawing.ImageMagick
|
||||||
return tempPath;
|
return tempPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<string> DownloadFont(string name, string url, IApplicationPaths paths, IHttpClient httpClient)
|
internal static async Task<string> DownloadFont(string name, string url, IApplicationPaths paths, IHttpClient httpClient, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
|
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
if (fileSystem.FileExists(filePath))
|
||||||
{
|
{
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
@ -103,11 +106,11 @@ namespace Emby.Drawing.ImageMagick
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Copy(tempPath, filePath, false);
|
fileSystem.CopyFile(tempPath, filePath, false);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,16 +2,19 @@
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace Emby.Drawing.ImageMagick
|
namespace Emby.Drawing.ImageMagick
|
||||||
{
|
{
|
||||||
public class StripCollageBuilder
|
public class StripCollageBuilder
|
||||||
{
|
{
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public StripCollageBuilder(IApplicationPaths appPaths)
|
public StripCollageBuilder(IApplicationPaths appPaths, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuildPosterCollage(List<string> paths, string outputPath, int width, int height, string text)
|
public void BuildPosterCollage(List<string> paths, string outputPath, int width, int height, string text)
|
||||||
|
@ -490,7 +493,7 @@ namespace Emby.Drawing.ImageMagick
|
||||||
|
|
||||||
private string MontserratLightFont
|
private string MontserratLightFont
|
||||||
{
|
{
|
||||||
get { return PlayedIndicatorDrawer.ExtractFont("MontserratLight.otf", _appPaths); }
|
get { return PlayedIndicatorDrawer.ExtractFont("MontserratLight.otf", _appPaths, _fileSystem); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Emby.Drawing.ImageMagick
|
||||||
pixel.Opacity = 0;
|
pixel.Opacity = 0;
|
||||||
pixel.Color = "white";
|
pixel.Color = "white";
|
||||||
draw.FillColor = pixel;
|
draw.FillColor = pixel;
|
||||||
draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths);
|
draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem);
|
||||||
draw.FontStyle = FontStyleType.NormalStyle;
|
draw.FontStyle = FontStyleType.NormalStyle;
|
||||||
draw.TextAlignment = TextAlignType.CenterAlign;
|
draw.TextAlignment = TextAlignType.CenterAlign;
|
||||||
draw.FontWeight = FontWeightType.RegularStyle;
|
draw.FontWeight = FontWeightType.RegularStyle;
|
||||||
|
|
|
@ -215,12 +215,12 @@ namespace Emby.Drawing
|
||||||
{
|
{
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
|
|
||||||
if (!File.Exists(cacheFilePath))
|
if (!_fileSystem.FileExists(cacheFilePath))
|
||||||
{
|
{
|
||||||
var newWidth = Convert.ToInt32(newSize.Width);
|
var newWidth = Convert.ToInt32(newSize.Width);
|
||||||
var newHeight = Convert.ToInt32(newSize.Height);
|
var newHeight = Convert.ToInt32(newSize.Height);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
||||||
|
|
||||||
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ namespace Emby.Drawing
|
||||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
// Check again in case of contention
|
// Check again in case of contention
|
||||||
if (File.Exists(croppedImagePath))
|
if (_fileSystem.FileExists(croppedImagePath))
|
||||||
{
|
{
|
||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
return GetResult(croppedImagePath);
|
return GetResult(croppedImagePath);
|
||||||
|
@ -280,7 +280,7 @@ namespace Emby.Drawing
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
|
||||||
|
|
||||||
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
imageProcessingLockTaken = true;
|
imageProcessingLockTaken = true;
|
||||||
|
@ -366,7 +366,7 @@ namespace Emby.Drawing
|
||||||
/// <returns>ImageSize.</returns>
|
/// <returns>ImageSize.</returns>
|
||||||
public ImageSize GetImageSize(string path)
|
public ImageSize GetImageSize(string path)
|
||||||
{
|
{
|
||||||
return GetImageSize(path, File.GetLastWriteTimeUtc(path), false);
|
return GetImageSize(path, _fileSystem.GetLastWriteTimeUtc(path), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageSize GetImageSize(ItemImageInfo info)
|
public ImageSize GetImageSize(ItemImageInfo info)
|
||||||
|
@ -452,7 +452,7 @@ namespace Emby.Drawing
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var path = ImageSizeFile;
|
var path = ImageSizeFile;
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
_jsonSerializer.SerializeToFile(_cachedImagedSizes, path);
|
_jsonSerializer.SerializeToFile(_cachedImagedSizes, path);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -624,7 +624,7 @@ namespace Emby.Drawing
|
||||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
// Check again in case of contention
|
// Check again in case of contention
|
||||||
if (File.Exists(enhancedImagePath))
|
if (_fileSystem.FileExists(enhancedImagePath))
|
||||||
{
|
{
|
||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
return enhancedImagePath;
|
return enhancedImagePath;
|
||||||
|
@ -634,7 +634,7 @@ namespace Emby.Drawing
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
|
||||||
|
|
||||||
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
using MediaBrowser.Common.IO;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Controller.Themes;
|
|
||||||
using MediaBrowser.Model.Themes;
|
|
||||||
using ServiceStack;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
|
||||||
{
|
|
||||||
[Route("/Themes", "GET", Summary = "Gets a list of available themes for an app")]
|
|
||||||
public class GetAppThemes : IReturn<List<AppThemeInfo>>
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string App { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Themes/Info", "GET", Summary = "Gets an app theme")]
|
|
||||||
public class GetAppTheme : IReturn<AppTheme>
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string App { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string Name { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Themes/Images", "GET", Summary = "Gets an app theme")]
|
|
||||||
public class GetAppThemeImage
|
|
||||||
{
|
|
||||||
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string App { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "Theme", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string Theme { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "CacheTag", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string CacheTag { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Themes", "POST", Summary = "Saves a theme")]
|
|
||||||
public class SaveTheme : AppTheme, IReturnVoid
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Authenticated]
|
|
||||||
public class AppThemeService : BaseApiService
|
|
||||||
{
|
|
||||||
private readonly IAppThemeManager _themeManager;
|
|
||||||
private readonly IFileSystem _fileSystem;
|
|
||||||
|
|
||||||
public AppThemeService(IAppThemeManager themeManager, IFileSystem fileSystem)
|
|
||||||
{
|
|
||||||
_themeManager = themeManager;
|
|
||||||
_fileSystem = fileSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetAppThemes request)
|
|
||||||
{
|
|
||||||
var result = _themeManager.GetThemes(request.App).ToList();
|
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetAppTheme request)
|
|
||||||
{
|
|
||||||
var result = _themeManager.GetTheme(request.App, request.Name);
|
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Post(SaveTheme request)
|
|
||||||
{
|
|
||||||
_themeManager.SaveTheme(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetAppThemeImage request)
|
|
||||||
{
|
|
||||||
var info = _themeManager.GetImageImageInfo(request.App, request.Theme, request.Name);
|
|
||||||
|
|
||||||
var cacheGuid = new Guid(info.CacheTag);
|
|
||||||
|
|
||||||
TimeSpan? cacheDuration = null;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.CacheTag) && cacheGuid == new Guid(request.CacheTag))
|
|
||||||
{
|
|
||||||
cacheDuration = TimeSpan.FromDays(365);
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentType = MimeTypes.GetMimeType(info.Path);
|
|
||||||
|
|
||||||
return ResultFactory.GetCachedResult(Request, cacheGuid, null, cacheDuration, () => _fileSystem.GetFileStream(info.Path, FileMode.Open, FileAccess.Read, FileShare.Read), contentType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
|
@ -96,13 +97,14 @@ namespace MediaBrowser.Api
|
||||||
/// The _network manager
|
/// The _network manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly INetworkManager _networkManager;
|
private readonly INetworkManager _networkManager;
|
||||||
|
private IFileSystem _fileSystem;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="EnvironmentService" /> class.
|
/// Initializes a new instance of the <see cref="EnvironmentService" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="networkManager">The network manager.</param>
|
/// <param name="networkManager">The network manager.</param>
|
||||||
/// <exception cref="System.ArgumentNullException">networkManager</exception>
|
/// <exception cref="System.ArgumentNullException">networkManager</exception>
|
||||||
public EnvironmentService(INetworkManager networkManager)
|
public EnvironmentService(INetworkManager networkManager, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
if (networkManager == null)
|
if (networkManager == null)
|
||||||
{
|
{
|
||||||
|
@ -110,6 +112,7 @@ namespace MediaBrowser.Api
|
||||||
}
|
}
|
||||||
|
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -222,8 +225,7 @@ namespace MediaBrowser.Api
|
||||||
private IEnumerable<FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
|
private IEnumerable<FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
|
||||||
{
|
{
|
||||||
// using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
|
// using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
|
||||||
var entries = new DirectoryInfo(request.Path).EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
|
var entries = _fileSystem.GetFileSystemEntries(request.Path).Where(i =>
|
||||||
.Concat<FileSystemInfo>(new DirectoryInfo(request.Path).EnumerateFiles("*", SearchOption.TopDirectoryOnly)).Where(i =>
|
|
||||||
{
|
{
|
||||||
if (!request.IncludeHidden && i.Attributes.HasFlag(FileAttributes.Hidden))
|
if (!request.IncludeHidden && i.Attributes.HasFlag(FileAttributes.Hidden))
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,8 +130,7 @@ namespace MediaBrowser.Api.Images
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(path)
|
return _fileSystem.GetFiles(path)
|
||||||
.GetFiles("*", SearchOption.AllDirectories)
|
|
||||||
.Where(i => BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.Ordinal))
|
.Where(i => BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.Ordinal))
|
||||||
.Select(i => new ImageByNameInfo
|
.Select(i => new ImageByNameInfo
|
||||||
{
|
{
|
||||||
|
@ -184,7 +183,7 @@ namespace MediaBrowser.Api.Images
|
||||||
|
|
||||||
var paths = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(_appPaths.GeneralPath, request.Name, filename + i)).ToList();
|
var paths = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(_appPaths.GeneralPath, request.Name, filename + i)).ToList();
|
||||||
|
|
||||||
var path = paths.FirstOrDefault(File.Exists) ?? paths.FirstOrDefault();
|
var path = paths.FirstOrDefault(_fileSystem.FileExists) ?? paths.FirstOrDefault();
|
||||||
|
|
||||||
return ToStaticFileResult(path);
|
return ToStaticFileResult(path);
|
||||||
}
|
}
|
||||||
|
@ -198,11 +197,11 @@ namespace MediaBrowser.Api.Images
|
||||||
{
|
{
|
||||||
var themeFolder = Path.Combine(_appPaths.RatingsPath, request.Theme);
|
var themeFolder = Path.Combine(_appPaths.RatingsPath, request.Theme);
|
||||||
|
|
||||||
if (Directory.Exists(themeFolder))
|
if (_fileSystem.DirectoryExists(themeFolder))
|
||||||
{
|
{
|
||||||
var path = BaseItem.SupportedImageExtensions
|
var path = BaseItem.SupportedImageExtensions
|
||||||
.Select(i => Path.Combine(themeFolder, request.Name + i))
|
.Select(i => Path.Combine(themeFolder, request.Name + i))
|
||||||
.FirstOrDefault(File.Exists);
|
.FirstOrDefault(_fileSystem.FileExists);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
@ -212,14 +211,14 @@ namespace MediaBrowser.Api.Images
|
||||||
|
|
||||||
var allFolder = Path.Combine(_appPaths.RatingsPath, "all");
|
var allFolder = Path.Combine(_appPaths.RatingsPath, "all");
|
||||||
|
|
||||||
if (Directory.Exists(allFolder))
|
if (_fileSystem.DirectoryExists(allFolder))
|
||||||
{
|
{
|
||||||
// Avoid implicitly captured closure
|
// Avoid implicitly captured closure
|
||||||
var currentRequest = request;
|
var currentRequest = request;
|
||||||
|
|
||||||
var path = BaseItem.SupportedImageExtensions
|
var path = BaseItem.SupportedImageExtensions
|
||||||
.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
||||||
.FirstOrDefault(File.Exists);
|
.FirstOrDefault(_fileSystem.FileExists);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
@ -239,10 +238,10 @@ namespace MediaBrowser.Api.Images
|
||||||
{
|
{
|
||||||
var themeFolder = Path.Combine(_appPaths.MediaInfoImagesPath, request.Theme);
|
var themeFolder = Path.Combine(_appPaths.MediaInfoImagesPath, request.Theme);
|
||||||
|
|
||||||
if (Directory.Exists(themeFolder))
|
if (_fileSystem.DirectoryExists(themeFolder))
|
||||||
{
|
{
|
||||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
|
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
|
||||||
.FirstOrDefault(File.Exists);
|
.FirstOrDefault(_fileSystem.FileExists);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
@ -252,13 +251,13 @@ namespace MediaBrowser.Api.Images
|
||||||
|
|
||||||
var allFolder = Path.Combine(_appPaths.MediaInfoImagesPath, "all");
|
var allFolder = Path.Combine(_appPaths.MediaInfoImagesPath, "all");
|
||||||
|
|
||||||
if (Directory.Exists(allFolder))
|
if (_fileSystem.DirectoryExists(allFolder))
|
||||||
{
|
{
|
||||||
// Avoid implicitly captured closure
|
// Avoid implicitly captured closure
|
||||||
var currentRequest = request;
|
var currentRequest = request;
|
||||||
|
|
||||||
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
|
||||||
.FirstOrDefault(File.Exists);
|
.FirstOrDefault(_fileSystem.FileExists);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
|
|
@ -237,7 +237,7 @@ namespace MediaBrowser.Api.Images
|
||||||
contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
|
contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(contentPath))
|
if (_fileSystem.FileExists(contentPath))
|
||||||
{
|
{
|
||||||
return ToStaticFileResult(contentPath);
|
return ToStaticFileResult(contentPath);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ namespace MediaBrowser.Api.Images
|
||||||
|
|
||||||
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
using (var stream = result.Content)
|
using (var stream = result.Content)
|
||||||
{
|
{
|
||||||
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
||||||
|
@ -290,7 +290,7 @@ namespace MediaBrowser.Api.Images
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
||||||
using (var writer = new StreamWriter(pointerCachePath))
|
using (var writer = new StreamWriter(pointerCachePath))
|
||||||
{
|
{
|
||||||
await writer.WriteAsync(fullCachePath).ConfigureAwait(false);
|
await writer.WriteAsync(fullCachePath).ConfigureAwait(false);
|
||||||
|
|
|
@ -200,7 +200,7 @@ namespace MediaBrowser.Api
|
||||||
//}
|
//}
|
||||||
item.ProviderIds = request.ProviderIds;
|
item.ProviderIds = request.ProviderIds;
|
||||||
|
|
||||||
var task = _providerManager.RefreshFullItem(item, new MetadataRefreshOptions
|
var task = _providerManager.RefreshFullItem(item, new MetadataRefreshOptions(_fileSystem)
|
||||||
{
|
{
|
||||||
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
|
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
|
||||||
ImageRefreshMode = ImageRefreshMode.FullRefresh,
|
ImageRefreshMode = ImageRefreshMode.FullRefresh,
|
||||||
|
@ -230,7 +230,7 @@ namespace MediaBrowser.Api
|
||||||
contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
|
contentPath = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(contentPath))
|
if (_fileSystem.FileExists(contentPath))
|
||||||
{
|
{
|
||||||
return ToStaticFileResult(contentPath);
|
return ToStaticFileResult(contentPath);
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(fullCachePath));
|
||||||
using (var stream = result.Content)
|
using (var stream = result.Content)
|
||||||
{
|
{
|
||||||
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
||||||
|
@ -280,7 +280,7 @@ namespace MediaBrowser.Api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
|
||||||
using (var writer = new StreamWriter(pointerCachePath))
|
using (var writer = new StreamWriter(pointerCachePath))
|
||||||
{
|
{
|
||||||
await writer.WriteAsync(fullCachePath).ConfigureAwait(false);
|
await writer.WriteAsync(fullCachePath).ConfigureAwait(false);
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
private MetadataRefreshOptions GetRefreshOptions(BaseRefreshRequest request)
|
private MetadataRefreshOptions GetRefreshOptions(BaseRefreshRequest request)
|
||||||
{
|
{
|
||||||
return new MetadataRefreshOptions(new DirectoryService())
|
return new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||||
{
|
{
|
||||||
MetadataRefreshMode = request.MetadataRefreshMode,
|
MetadataRefreshMode = request.MetadataRefreshMode,
|
||||||
ImageRefreshMode = request.ImageRefreshMode,
|
ImageRefreshMode = request.ImageRefreshMode,
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace MediaBrowser.Api.Library
|
||||||
var rootFolderPath = appPaths.DefaultUserViewsPath;
|
var rootFolderPath = appPaths.DefaultUserViewsPath;
|
||||||
var path = Path.Combine(rootFolderPath, virtualFolderName);
|
var path = Path.Combine(rootFolderPath, virtualFolderName);
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!fileSystem.DirectoryExists(path))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
|
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ namespace MediaBrowser.Api.Library
|
||||||
/// <exception cref="System.ArgumentException">The path is not valid.</exception>
|
/// <exception cref="System.ArgumentException">The path is not valid.</exception>
|
||||||
public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, IServerApplicationPaths appPaths)
|
public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, IServerApplicationPaths appPaths)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(path))
|
if (!fileSystem.DirectoryExists(path))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException("The path does not exist.");
|
throw new DirectoryNotFoundException("The path does not exist.");
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace MediaBrowser.Api.Library
|
||||||
|
|
||||||
var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
|
var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
|
||||||
|
|
||||||
while (File.Exists(lnk))
|
while (fileSystem.FileExists(lnk))
|
||||||
{
|
{
|
||||||
shortcutFilename += "1";
|
shortcutFilename += "1";
|
||||||
lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
|
lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
|
||||||
|
|
|
@ -557,7 +557,7 @@ namespace MediaBrowser.Api.Library
|
||||||
{
|
{
|
||||||
throw new ArgumentException("This command cannot be used for remote or virtual items.");
|
throw new ArgumentException("This command cannot be used for remote or virtual items.");
|
||||||
}
|
}
|
||||||
if (Directory.Exists(item.Path))
|
if (_fileSystem.DirectoryExists(item.Path))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("This command cannot be used for directories.");
|
throw new ArgumentException("This command cannot be used for directories.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ namespace MediaBrowser.Api.Library
|
||||||
|
|
||||||
var virtualFolderPath = Path.Combine(rootFolderPath, name);
|
var virtualFolderPath = Path.Combine(rootFolderPath, name);
|
||||||
|
|
||||||
if (Directory.Exists(virtualFolderPath))
|
if (_fileSystem.DirectoryExists(virtualFolderPath))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("There is already a media collection with the name " + name + ".");
|
throw new ArgumentException("There is already a media collection with the name " + name + ".");
|
||||||
}
|
}
|
||||||
|
@ -204,13 +204,13 @@ namespace MediaBrowser.Api.Library
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(virtualFolderPath);
|
_fileSystem.CreateDirectory(virtualFolderPath);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.CollectionType))
|
if (!string.IsNullOrEmpty(request.CollectionType))
|
||||||
{
|
{
|
||||||
var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection");
|
var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection");
|
||||||
|
|
||||||
File.Create(path);
|
_fileSystem.CreateFile(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -256,12 +256,12 @@ namespace MediaBrowser.Api.Library
|
||||||
var currentPath = Path.Combine(rootFolderPath, request.Name);
|
var currentPath = Path.Combine(rootFolderPath, request.Name);
|
||||||
var newPath = Path.Combine(rootFolderPath, request.NewName);
|
var newPath = Path.Combine(rootFolderPath, request.NewName);
|
||||||
|
|
||||||
if (!Directory.Exists(currentPath))
|
if (!_fileSystem.DirectoryExists(currentPath))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException("The media collection does not exist");
|
throw new DirectoryNotFoundException("The media collection does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath))
|
if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && _fileSystem.DirectoryExists(newPath))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("There is already a media collection with the name " + newPath + ".");
|
throw new ArgumentException("There is already a media collection with the name " + newPath + ".");
|
||||||
}
|
}
|
||||||
|
@ -276,11 +276,11 @@ namespace MediaBrowser.Api.Library
|
||||||
//Create an unique name
|
//Create an unique name
|
||||||
var temporaryName = Guid.NewGuid().ToString();
|
var temporaryName = Guid.NewGuid().ToString();
|
||||||
var temporaryPath = Path.Combine(rootFolderPath, temporaryName);
|
var temporaryPath = Path.Combine(rootFolderPath, temporaryName);
|
||||||
Directory.Move(currentPath, temporaryPath);
|
_fileSystem.MoveDirectory(currentPath, temporaryPath);
|
||||||
currentPath = temporaryPath;
|
currentPath = temporaryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.Move(currentPath, newPath);
|
_fileSystem.MoveDirectory(currentPath, newPath);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -319,7 +319,7 @@ namespace MediaBrowser.Api.Library
|
||||||
|
|
||||||
var path = Path.Combine(rootFolderPath, request.Name);
|
var path = Path.Combine(rootFolderPath, request.Name);
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!_fileSystem.DirectoryExists(path))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException("The media folder does not exist");
|
throw new DirectoryNotFoundException("The media folder does not exist");
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
<AssemblyName>MediaBrowser.Api</AssemblyName>
|
<AssemblyName>MediaBrowser.Api</AssemblyName>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<ProductVersion>10.0.0</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
|
<ReleaseVersion>
|
||||||
|
</ReleaseVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -25,7 +25,6 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
|
@ -34,7 +33,6 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release Mono|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release Mono|AnyCPU' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
|
@ -43,16 +41,11 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="MoreLinq, Version=1.1.18418.0, Culture=neutral, PublicKeyToken=384d532d7e88985d, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\morelinq.1.1.1\lib\net35\MoreLinq.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
@ -64,12 +57,14 @@
|
||||||
<Reference Include="ServiceStack.Text">
|
<Reference Include="ServiceStack.Text">
|
||||||
<HintPath>..\ThirdParty\ServiceStack.Text\ServiceStack.Text.dll</HintPath>
|
<HintPath>..\ThirdParty\ServiceStack.Text\ServiceStack.Text.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="MoreLinq">
|
||||||
|
<HintPath>..\packages\morelinq.1.1.1\lib\net35\MoreLinq.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\SharedVersion.cs">
|
<Compile Include="..\SharedVersion.cs">
|
||||||
<Link>Properties\SharedVersion.cs</Link>
|
<Link>Properties\SharedVersion.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="AppThemeService.cs" />
|
|
||||||
<Compile Include="BrandingService.cs" />
|
<Compile Include="BrandingService.cs" />
|
||||||
<Compile Include="ChannelService.cs" />
|
<Compile Include="ChannelService.cs" />
|
||||||
<Compile Include="ConnectService.cs" />
|
<Compile Include="ConnectService.cs" />
|
||||||
|
|
|
@ -889,7 +889,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
CancellationTokenSource cancellationTokenSource,
|
CancellationTokenSource cancellationTokenSource,
|
||||||
string workingDirectory = null)
|
string workingDirectory = null)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
|
|
||||||
await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false);
|
await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -942,7 +942,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
Logger.Info(commandLineLogMessage);
|
Logger.Info(commandLineLogMessage);
|
||||||
|
|
||||||
var logFilePath = Path.Combine(ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "transcode-" + Guid.NewGuid() + ".txt");
|
var logFilePath = Path.Combine(ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, "transcode-" + Guid.NewGuid() + ".txt");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
||||||
|
|
||||||
// FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
|
// FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
|
||||||
state.LogFileStream = FileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true);
|
state.LogFileStream = FileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true);
|
||||||
|
@ -972,7 +972,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
StartStreamingLog(transcodingJob, state, process.StandardError.BaseStream, state.LogFileStream);
|
StartStreamingLog(transcodingJob, state, process.StandardError.BaseStream, state.LogFileStream);
|
||||||
|
|
||||||
// Wait for the file to exist before proceeeding
|
// Wait for the file to exist before proceeeding
|
||||||
while (!File.Exists(state.WaitForPath ?? outputPath) && !transcodingJob.HasExited)
|
while (!FileSystem.FileExists(state.WaitForPath ?? outputPath) && !transcodingJob.HasExited)
|
||||||
{
|
{
|
||||||
await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);
|
await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ namespace MediaBrowser.Api.Playback.Dash
|
||||||
|
|
||||||
var workingDirectory = Path.Combine(Path.GetDirectoryName(playlistPath), (startNumber == -1 ? 0 : startNumber).ToString(CultureInfo.InvariantCulture));
|
var workingDirectory = Path.Combine(Path.GetDirectoryName(playlistPath), (startNumber == -1 ? 0 : startNumber).ToString(CultureInfo.InvariantCulture));
|
||||||
state.WaitForPath = Path.Combine(workingDirectory, Path.GetFileName(playlistPath));
|
state.WaitForPath = Path.Combine(workingDirectory, Path.GetFileName(playlistPath));
|
||||||
Directory.CreateDirectory(workingDirectory);
|
FileSystem.CreateDirectory(workingDirectory);
|
||||||
job = await StartFfMpeg(state, playlistPath, cancellationTokenSource, workingDirectory).ConfigureAwait(false);
|
job = await StartFfMpeg(state, playlistPath, cancellationTokenSource, workingDirectory).ConfigureAwait(false);
|
||||||
await WaitForMinimumDashSegmentCount(Path.Combine(workingDirectory, Path.GetFileName(playlistPath)), 1, cancellationTokenSource.Token).ConfigureAwait(false);
|
await WaitForMinimumDashSegmentCount(Path.Combine(workingDirectory, Path.GetFileName(playlistPath)), 1, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -328,8 +328,7 @@ namespace MediaBrowser.Api.Playback.Dash
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(folder)
|
return fileSystem.GetFiles(folder)
|
||||||
.EnumerateFiles("*", SearchOption.AllDirectories)
|
|
||||||
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase))
|
||||||
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
|
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
|
||||||
.Take(count)
|
.Take(count)
|
||||||
|
@ -348,12 +347,12 @@ namespace MediaBrowser.Api.Playback.Dash
|
||||||
if (requestedIndex == -1)
|
if (requestedIndex == -1)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(folder, "0", "stream" + representationId + "-" + "init" + segmentExtension);
|
var path = Path.Combine(folder, "0", "stream" + representationId + "-" + "init" + segmentExtension);
|
||||||
return File.Exists(path) ? path : null;
|
return FileSystem.FileExists(path) ? path : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var subfolder in new DirectoryInfo(folder).EnumerateDirectories().ToList())
|
foreach (var subfolder in FileSystem.GetDirectories(folder).ToList())
|
||||||
{
|
{
|
||||||
var subfolderName = Path.GetFileNameWithoutExtension(subfolder.FullName);
|
var subfolderName = Path.GetFileNameWithoutExtension(subfolder.FullName);
|
||||||
int startNumber;
|
int startNumber;
|
||||||
|
@ -361,7 +360,7 @@ namespace MediaBrowser.Api.Playback.Dash
|
||||||
{
|
{
|
||||||
var segmentIndex = requestedIndex - startNumber + 1;
|
var segmentIndex = requestedIndex - startNumber + 1;
|
||||||
var path = Path.Combine(folder, subfolderName, "stream" + representationId + "-" + segmentIndex.ToString("00000", CultureInfo.InvariantCulture) + segmentExtension);
|
var path = Path.Combine(folder, subfolderName, "stream" + representationId + "-" + segmentIndex.ToString("00000", CultureInfo.InvariantCulture) + segmentExtension);
|
||||||
if (File.Exists(path))
|
if (FileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,12 +90,12 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
TranscodingJob job = null;
|
TranscodingJob job = null;
|
||||||
var playlist = state.OutputFilePath;
|
var playlist = state.OutputFilePath;
|
||||||
|
|
||||||
if (!File.Exists(playlist))
|
if (!FileSystem.FileExists(playlist))
|
||||||
{
|
{
|
||||||
await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!File.Exists(playlist))
|
if (!FileSystem.FileExists(playlist))
|
||||||
{
|
{
|
||||||
// If the playlist doesn't already exist, startup ffmpeg
|
// If the playlist doesn't already exist, startup ffmpeg
|
||||||
try
|
try
|
||||||
|
|
|
@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
|
|
||||||
TranscodingJob job = null;
|
TranscodingJob job = null;
|
||||||
|
|
||||||
if (File.Exists(segmentPath))
|
if (FileSystem.FileExists(segmentPath))
|
||||||
{
|
{
|
||||||
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
||||||
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -174,7 +174,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(segmentPath))
|
if (FileSystem.FileExists(segmentPath))
|
||||||
{
|
{
|
||||||
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
||||||
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -386,8 +386,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(folder)
|
return fileSystem.GetFiles(folder)
|
||||||
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
|
|
||||||
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase) && Path.GetFileNameWithoutExtension(i.Name).StartsWith(filePrefix, StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase) && Path.GetFileNameWithoutExtension(i.Name).StartsWith(filePrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
|
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
@ -432,7 +431,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// If all transcoding has completed, just return immediately
|
// If all transcoding has completed, just return immediately
|
||||||
if (transcodingJob != null && transcodingJob.HasExited && File.Exists(segmentPath))
|
if (transcodingJob != null && transcodingJob.HasExited && FileSystem.FileExists(segmentPath))
|
||||||
{
|
{
|
||||||
return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob);
|
return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob);
|
||||||
}
|
}
|
||||||
|
@ -452,7 +451,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
// If it appears in the playlist, it's done
|
// If it appears in the playlist, it's done
|
||||||
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
|
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
if (File.Exists(segmentPath))
|
if (FileSystem.FileExists(segmentPath))
|
||||||
{
|
{
|
||||||
return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob);
|
return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace MediaBrowser.Api.Playback.Progressive
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputPath = state.OutputFilePath;
|
var outputPath = state.OutputFilePath;
|
||||||
var outputPathExists = File.Exists(outputPath);
|
var outputPathExists = FileSystem.FileExists(outputPath);
|
||||||
|
|
||||||
var isTranscodeCached = outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive);
|
var isTranscodeCached = outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive);
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ namespace MediaBrowser.Api.Playback.Progressive
|
||||||
{
|
{
|
||||||
TranscodingJob job;
|
TranscodingJob job;
|
||||||
|
|
||||||
if (!File.Exists(outputPath))
|
if (!FileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
job = await StartFfMpeg(state, outputPath, cancellationTokenSource).ConfigureAwait(false);
|
job = await StartFfMpeg(state, outputPath, cancellationTokenSource).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ namespace MediaBrowser.Api.Subtitles
|
||||||
await _subtitleManager.DownloadSubtitles(video, request.SubtitleId, CancellationToken.None)
|
await _subtitleManager.DownloadSubtitles(video, request.SubtitleId, CancellationToken.None)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
_providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions());
|
_providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(_fileSystem));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -122,8 +122,7 @@ namespace MediaBrowser.Api.System
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
files = new DirectoryInfo(_appPaths.LogDirectoryPath)
|
files = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
|
||||||
.EnumerateFiles("*", SearchOption.AllDirectories)
|
|
||||||
.Where(i => string.Equals(i.Extension, ".txt", StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Extension, ".txt", StringComparison.OrdinalIgnoreCase))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -149,8 +148,7 @@ namespace MediaBrowser.Api.System
|
||||||
|
|
||||||
public object Get(GetLogFile request)
|
public object Get(GetLogFile request)
|
||||||
{
|
{
|
||||||
var file = new DirectoryInfo(_appPaths.LogDirectoryPath)
|
var file = _fileSystem.GetFiles(_appPaths.LogDirectoryPath)
|
||||||
.EnumerateFiles("*", SearchOption.AllDirectories)
|
|
||||||
.First(i => string.Equals(i.Name, request.Name, StringComparison.OrdinalIgnoreCase));
|
.First(i => string.Equals(i.Name, request.Name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
return ResultFactory.GetStaticFileResult(Request, file.FullName, FileShare.ReadWrite);
|
return ResultFactory.GetStaticFileResult(Request, file.FullName, FileShare.ReadWrite);
|
||||||
|
|
|
@ -7,6 +7,7 @@ using SharpCompress.Reader;
|
||||||
using SharpCompress.Reader.Zip;
|
using SharpCompress.Reader.Zip;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.Archiving
|
namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
{
|
{
|
||||||
|
@ -15,7 +16,14 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ZipClient : IZipClient
|
public class ZipClient : IZipClient
|
||||||
{
|
{
|
||||||
/// <summary>
|
private IFileSystem _fileSystem;
|
||||||
|
|
||||||
|
public ZipClient(IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
/// Extracts all.
|
/// Extracts all.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourceFile">The source file.</param>
|
/// <param name="sourceFile">The source file.</param>
|
||||||
|
@ -23,7 +31,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||||
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||||
{
|
{
|
||||||
using (var fileStream = File.OpenRead(sourceFile))
|
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||||
{
|
{
|
||||||
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
|
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +81,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||||
public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||||
{
|
{
|
||||||
using (var fileStream = File.OpenRead(sourceFile))
|
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||||
{
|
{
|
||||||
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
|
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +120,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||||
public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||||
{
|
{
|
||||||
using (var fileStream = File.OpenRead(sourceFile))
|
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||||
{
|
{
|
||||||
ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles);
|
ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles);
|
||||||
}
|
}
|
||||||
|
@ -150,7 +158,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||||
public void ExtractAllFromRar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
public void ExtractAllFromRar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||||
{
|
{
|
||||||
using (var fileStream = File.OpenRead(sourceFile))
|
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||||
{
|
{
|
||||||
ExtractAllFromRar(fileStream, targetPath, overwriteExistingFiles);
|
ExtractAllFromRar(fileStream, targetPath, overwriteExistingFiles);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _XML serializer
|
/// The _XML serializer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly IXmlSerializer XmlSerializer = new XmlSerializer();
|
protected readonly IXmlSerializer XmlSerializer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets assemblies that failed to load
|
/// Gets assemblies that failed to load
|
||||||
|
@ -180,7 +180,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
{
|
{
|
||||||
if (_deviceId == null)
|
if (_deviceId == null)
|
||||||
{
|
{
|
||||||
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"));
|
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"), FileSystemManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _deviceId.Value;
|
return _deviceId.Value;
|
||||||
|
@ -199,6 +199,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
ILogManager logManager,
|
ILogManager logManager,
|
||||||
IFileSystem fileSystem)
|
IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
|
XmlSerializer = new MediaBrowser.Common.Implementations.Serialization.XmlSerializer (fileSystem);
|
||||||
FailedAssemblies = new List<string>();
|
FailedAssemblies = new List<string>();
|
||||||
|
|
||||||
ApplicationPaths = applicationPaths;
|
ApplicationPaths = applicationPaths;
|
||||||
|
@ -473,7 +474,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
|
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
|
||||||
RegisterSingleInstance(InstallationManager);
|
RegisterSingleInstance(InstallationManager);
|
||||||
|
|
||||||
ZipClient = new ZipClient();
|
ZipClient = new ZipClient(FileSystemManager);
|
||||||
RegisterSingleInstance(ZipClient);
|
RegisterSingleInstance(ZipClient);
|
||||||
|
|
||||||
IsoManager = new IsoManager();
|
IsoManager = new IsoManager();
|
||||||
|
@ -650,7 +651,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Assembly.Load(File.ReadAllBytes((file)));
|
return Assembly.Load(FileSystemManager.ReadAllBytes((file)));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
{
|
{
|
||||||
_dataDirectory = Path.Combine(ProgramDataPath, "data");
|
_dataDirectory = Path.Combine(ProgramDataPath, "data");
|
||||||
|
|
||||||
Directory.CreateDirectory(_dataDirectory);
|
FileSystem.CreateDirectory(_dataDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _dataDirectory;
|
return _dataDirectory;
|
||||||
|
@ -152,7 +152,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
{
|
{
|
||||||
_cachePath = Path.Combine(ProgramDataPath, "cache");
|
_cachePath = Path.Combine(ProgramDataPath, "cache");
|
||||||
|
|
||||||
Directory.CreateDirectory(_cachePath);
|
FileSystem.CreateDirectory(_cachePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cachePath;
|
return _cachePath;
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
{
|
{
|
||||||
var path = CommonApplicationPaths.SystemConfigurationFilePath;
|
var path = CommonApplicationPaths.SystemConfigurationFilePath;
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_configurationSyncLock)
|
lock (_configurationSyncLock)
|
||||||
{
|
{
|
||||||
|
@ -276,7 +276,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
|
_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
|
||||||
|
|
||||||
var path = GetConfigurationFile(key);
|
var path = GetConfigurationFile(key);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_configurationSyncLock)
|
lock (_configurationSyncLock)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.Configuration
|
namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
{
|
{
|
||||||
|
@ -18,7 +19,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <param name="xmlSerializer">The XML serializer.</param>
|
/// <param name="xmlSerializer">The XML serializer.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer)
|
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
object configuration;
|
object configuration;
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
// Use try/catch to avoid the extra file system lookup using File.Exists
|
// Use try/catch to avoid the extra file system lookup using File.Exists
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buffer = File.ReadAllBytes(path);
|
buffer = fileSystem.ReadAllBytes(path);
|
||||||
|
|
||||||
configuration = xmlSerializer.DeserializeFromBytes(type, buffer);
|
configuration = xmlSerializer.DeserializeFromBytes(type, buffer);
|
||||||
}
|
}
|
||||||
|
@ -46,10 +47,10 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||||
// If the file didn't exist before, or if something has changed, re-save
|
// If the file didn't exist before, or if something has changed, re-save
|
||||||
if (buffer == null || !buffer.SequenceEqual(newBytes))
|
if (buffer == null || !buffer.SequenceEqual(newBytes))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
// Save it after load in case we got new items
|
// Save it after load in case we got new items
|
||||||
File.WriteAllBytes(path, newBytes);
|
fileSystem.WriteAllBytes(path, newBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
|
|
|
@ -3,13 +3,15 @@ using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.Devices
|
namespace MediaBrowser.Common.Implementations.Devices
|
||||||
{
|
{
|
||||||
public class DeviceId
|
public class DeviceId
|
||||||
{
|
{
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
private readonly object _syncLock = new object();
|
private readonly object _syncLock = new object();
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||||
{
|
{
|
||||||
lock (_syncLock)
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
var value = File.ReadAllText(CachePath, Encoding.UTF8);
|
var value = _fileSystem.ReadAllText(CachePath, Encoding.UTF8);
|
||||||
|
|
||||||
Guid guid;
|
Guid guid;
|
||||||
if (Guid.TryParse(value, out guid))
|
if (Guid.TryParse(value, out guid))
|
||||||
|
@ -55,11 +57,11 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||||
{
|
{
|
||||||
var path = CachePath;
|
var path = CachePath;
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_syncLock)
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
File.WriteAllText(path, id, Encoding.UTF8);
|
_fileSystem.WriteAllText(path, id, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -88,10 +90,15 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||||
|
|
||||||
private string _id;
|
private string _id;
|
||||||
|
|
||||||
public DeviceId(IApplicationPaths appPaths, ILogger logger)
|
public DeviceId(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
|
if (fileSystem == null) {
|
||||||
|
throw new ArgumentNullException ("fileSystem");
|
||||||
|
}
|
||||||
|
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Value
|
public string Value
|
||||||
|
|
|
@ -355,7 +355,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
|
|
||||||
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
|
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
||||||
|
|
||||||
using (var responseStream = response.Content)
|
using (var responseStream = response.Content)
|
||||||
{
|
{
|
||||||
|
@ -599,7 +599,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||||
{
|
{
|
||||||
ValidateParams(options);
|
ValidateParams(options);
|
||||||
|
|
||||||
Directory.CreateDirectory(_appPaths.TempDirectory);
|
_fileSystem.CreateDirectory(_appPaths.TempDirectory);
|
||||||
|
|
||||||
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
|
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.IO
|
namespace MediaBrowser.Common.Implementations.IO
|
||||||
{
|
{
|
||||||
|
@ -75,7 +77,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||||
|
|
||||||
if (string.Equals(Path.GetExtension(filename), ".mblink", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(Path.GetExtension(filename), ".mblink", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var path = File.ReadAllText(filename);
|
var path = ReadAllText(filename);
|
||||||
|
|
||||||
return NormalizePath(path);
|
return NormalizePath(path);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||||
throw new ArgumentNullException("target");
|
throw new ArgumentNullException("target");
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(shortcutPath, target);
|
_fileSystem.WriteAllText(shortcutPath, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -230,7 +232,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||||
/// <param name="share">The share.</param>
|
/// <param name="share">The share.</param>
|
||||||
/// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
|
/// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
|
||||||
/// <returns>FileStream.</returns>
|
/// <returns>FileStream.</returns>
|
||||||
public FileStream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false)
|
public Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false)
|
||||||
{
|
{
|
||||||
if (_supportsAsyncFileStreams && isAsync)
|
if (_supportsAsyncFileStreams && isAsync)
|
||||||
{
|
{
|
||||||
|
@ -264,11 +266,11 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||||
RemoveHiddenAttribute(file1);
|
RemoveHiddenAttribute(file1);
|
||||||
RemoveHiddenAttribute(file2);
|
RemoveHiddenAttribute(file2);
|
||||||
|
|
||||||
File.Copy(file1, temp1, true);
|
CopyFile(file1, temp1, true);
|
||||||
File.Copy(file2, temp2, true);
|
CopyFile(file2, temp2, true);
|
||||||
|
|
||||||
File.Copy(temp1, file2, true);
|
CopyFile(temp1, file2, true);
|
||||||
File.Copy(temp2, file1, true);
|
CopyFile(temp2, file1, true);
|
||||||
|
|
||||||
DeleteFile(temp1);
|
DeleteFile(temp1);
|
||||||
DeleteFile(temp2);
|
DeleteFile(temp2);
|
||||||
|
@ -410,24 +412,42 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||||
//return Path.IsPathRooted(path);
|
//return Path.IsPathRooted(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFile(string path, bool sendToRecycleBin)
|
public void DeleteFile(string path)
|
||||||
{
|
{
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin)
|
|
||||||
{
|
|
||||||
Directory.Delete(path, recursive);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteFile(string path)
|
|
||||||
{
|
|
||||||
DeleteFile(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteDirectory(string path, bool recursive)
|
public void DeleteDirectory(string path, bool recursive)
|
||||||
{
|
{
|
||||||
DeleteDirectory(path, recursive, false);
|
Directory.Delete(path, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CreateDirectory(string path)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false)
|
||||||
|
{
|
||||||
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||||
|
|
||||||
|
return new DirectoryInfo (path).EnumerateDirectories("*", searchOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FileInfo> GetFiles(string path, bool recursive = false)
|
||||||
|
{
|
||||||
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||||
|
|
||||||
|
return new DirectoryInfo (path).EnumerateFiles("*", searchOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool recursive = false)
|
||||||
|
{
|
||||||
|
var directoryInfo = new DirectoryInfo (path);
|
||||||
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||||
|
|
||||||
|
return directoryInfo.EnumerateDirectories("*", searchOption)
|
||||||
|
.Concat<FileSystemInfo>(directoryInfo.EnumerateFiles("*", searchOption));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Logging
|
||||||
{
|
{
|
||||||
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt");
|
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt");
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(LogFilePath));
|
||||||
|
|
||||||
AddFileTarget(LogFilePath, level);
|
AddFileTarget(LogFilePath, level);
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
|
||||||
_lastExecutionResult = value;
|
_lastExecutionResult = value;
|
||||||
|
|
||||||
var path = GetHistoryFilePath();
|
var path = GetHistoryFilePath();
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_lastExecutionResultSyncLock)
|
lock (_lastExecutionResultSyncLock)
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
|
||||||
{
|
{
|
||||||
var path = GetConfigurationFilePath();
|
var path = GetConfigurationFilePath();
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path);
|
JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||||
/// <param name="progress">The progress.</param>
|
/// <param name="progress">The progress.</param>
|
||||||
private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress<double> progress)
|
private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress<double> progress)
|
||||||
{
|
{
|
||||||
var filesToDelete = new DirectoryInfo(directory).EnumerateFiles("*", SearchOption.AllDirectories)
|
var filesToDelete = _fileSystem.GetFiles(directory, true)
|
||||||
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
@ -120,14 +120,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DeleteEmptyFolders(string parent)
|
private void DeleteEmptyFolders(string parent)
|
||||||
{
|
{
|
||||||
foreach (var directory in Directory.GetDirectories(parent))
|
foreach (var directory in Directory.GetDirectories(parent))
|
||||||
{
|
{
|
||||||
DeleteEmptyFolders(directory);
|
DeleteEmptyFolders(directory);
|
||||||
if (!Directory.EnumerateFileSystemEntries(directory).Any())
|
if (!Directory.EnumerateFileSystemEntries(directory).Any())
|
||||||
{
|
{
|
||||||
Directory.Delete(directory, false);
|
_fileSystem.DeleteDirectory(directory, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||||
// Delete log files more than n days old
|
// Delete log files more than n days old
|
||||||
var minDateModified = DateTime.UtcNow.AddDays(-(ConfigurationManager.CommonConfiguration.LogFileRetentionDays));
|
var minDateModified = DateTime.UtcNow.AddDays(-(ConfigurationManager.CommonConfiguration.LogFileRetentionDays));
|
||||||
|
|
||||||
var filesToDelete = new DirectoryInfo(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
|
var filesToDelete = _fileSystem.GetFiles(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath, true)
|
||||||
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
|
@ -99,15 +99,15 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contents = File.ReadAllLines(licenseFile);
|
contents = _fileSystem.ReadAllLines(licenseFile);
|
||||||
}
|
}
|
||||||
catch (DirectoryNotFoundException)
|
catch (DirectoryNotFoundException)
|
||||||
{
|
{
|
||||||
(File.Create(licenseFile)).Close();
|
(_fileSystem.CreateFile(licenseFile)).Close();
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
(File.Create(licenseFile)).Close();
|
(_fileSystem.CreateFile(licenseFile)).Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contents != null && contents.Length > 0)
|
if (contents != null && contents.Length > 0)
|
||||||
|
@ -150,8 +150,8 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
}
|
}
|
||||||
|
|
||||||
var licenseFile = Filename;
|
var licenseFile = Filename;
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||||
lock (_fileLock) File.WriteAllLines(licenseFile, lines);
|
lock (_fileLock) _fileSystem.WriteAllLines(licenseFile, lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||||
throw new ArgumentNullException("file");
|
throw new ArgumentNullException("file");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (Stream stream = File.Open(file, FileMode.Create))
|
using (Stream stream = _fileSystem.GetFileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||||
{
|
{
|
||||||
SerializeToStream(obj, stream);
|
SerializeToStream(obj, stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.Serialization
|
namespace MediaBrowser.Common.Implementations.Serialization
|
||||||
{
|
{
|
||||||
|
@ -11,6 +12,13 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class XmlSerializer : IXmlSerializer
|
public class XmlSerializer : IXmlSerializer
|
||||||
{
|
{
|
||||||
|
private IFileSystem _fileSystem;
|
||||||
|
|
||||||
|
public XmlSerializer(IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
|
||||||
// Need to cache these
|
// Need to cache these
|
||||||
// http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html
|
// http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html
|
||||||
private readonly ConcurrentDictionary<string, System.Xml.Serialization.XmlSerializer> _serializers =
|
private readonly ConcurrentDictionary<string, System.Xml.Serialization.XmlSerializer> _serializers =
|
||||||
|
@ -83,7 +91,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public object DeserializeFromFile(Type type, string file)
|
public object DeserializeFromFile(Type type, string file)
|
||||||
{
|
{
|
||||||
using (var stream = File.OpenRead(file))
|
using (var stream = _fileSystem.OpenRead(file))
|
||||||
{
|
{
|
||||||
return DeserializeFromStream(type, stream);
|
return DeserializeFromStream(type, stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -553,7 +553,7 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||||
if (packageChecksum != Guid.Empty) // support for legacy uploads for now
|
if (packageChecksum != Guid.Empty) // support for legacy uploads for now
|
||||||
{
|
{
|
||||||
using (var crypto = new MD5CryptoServiceProvider())
|
using (var crypto = new MD5CryptoServiceProvider())
|
||||||
using (var stream = new BufferedStream(File.OpenRead(tempFile), 100000))
|
using (var stream = new BufferedStream(_fileSystem.OpenRead(tempFile), 100000))
|
||||||
{
|
{
|
||||||
var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
|
var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
|
||||||
if (check != packageChecksum)
|
if (check != packageChecksum)
|
||||||
|
@ -568,12 +568,12 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||||
// Success - move it to the real target
|
// Success - move it to the real target
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(target));
|
||||||
File.Copy(tempFile, target, true);
|
_fileSystem.CopyFile(tempFile, target, true);
|
||||||
//If it is an archive - write out a version file so we know what it is
|
//If it is an archive - write out a version file so we know what it is
|
||||||
if (isArchive)
|
if (isArchive)
|
||||||
{
|
{
|
||||||
File.WriteAllText(target + ".ver", package.versionStr);
|
_fileSystem.WriteAllText(target + ".ver", package.versionStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.IO
|
namespace MediaBrowser.Common.IO
|
||||||
{
|
{
|
||||||
|
@ -73,7 +75,9 @@ namespace MediaBrowser.Common.IO
|
||||||
/// <param name="share">The share.</param>
|
/// <param name="share">The share.</param>
|
||||||
/// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
|
/// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
|
||||||
/// <returns>FileStream.</returns>
|
/// <returns>FileStream.</returns>
|
||||||
FileStream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false);
|
Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false);
|
||||||
|
|
||||||
|
Stream OpenRead(String path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Swaps the files.
|
/// Swaps the files.
|
||||||
|
@ -134,21 +138,6 @@ namespace MediaBrowser.Common.IO
|
||||||
/// <returns><c>true</c> if [is path file] [the specified path]; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if [is path file] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||||
bool IsPathFile(string path);
|
bool IsPathFile(string path);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes the file.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">The path.</param>
|
|
||||||
/// <param name="sendToRecycleBin">if set to <c>true</c> [send to recycle bin].</param>
|
|
||||||
void DeleteFile(string path, bool sendToRecycleBin);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes the directory.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">The path.</param>
|
|
||||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
|
||||||
/// <param name="sendToRecycleBin">if set to <c>true</c> [send to recycle bin].</param>
|
|
||||||
void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the file.
|
/// Deletes the file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -161,5 +150,41 @@ namespace MediaBrowser.Common.IO
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
||||||
void DeleteDirectory(string path, bool recursive);
|
void DeleteDirectory(string path, bool recursive);
|
||||||
|
|
||||||
|
IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false);
|
||||||
|
|
||||||
|
IEnumerable<FileInfo> GetFiles(string path, bool recursive = false);
|
||||||
|
|
||||||
|
IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool recursive = false);
|
||||||
|
|
||||||
|
void CreateDirectory(string path);
|
||||||
|
|
||||||
|
void CopyFile(string source, string target, bool overwrite);
|
||||||
|
|
||||||
|
void MoveFile(string source, string target);
|
||||||
|
|
||||||
|
void MoveDirectory(string source, string target);
|
||||||
|
|
||||||
|
bool DirectoryExists(string path);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
string[] ReadAllLines(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,7 +683,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
var files = fileSystemChildren.OfType<DirectoryInfo>()
|
var files = fileSystemChildren.OfType<DirectoryInfo>()
|
||||||
.Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
|
||||||
.SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
|
.SelectMany(i => directoryService.GetFiles(i.FullName))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Support plex/xbmc convention
|
// Support plex/xbmc convention
|
||||||
|
@ -719,7 +719,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
var files = fileSystemChildren.OfType<DirectoryInfo>()
|
var files = fileSystemChildren.OfType<DirectoryInfo>()
|
||||||
.Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
|
||||||
.SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly));
|
.SelectMany(i => directoryService.GetFiles(i.FullName));
|
||||||
|
|
||||||
return LibraryManager.ResolvePaths(files, directoryService, null)
|
return LibraryManager.ResolvePaths(files, directoryService, null)
|
||||||
.OfType<Video>()
|
.OfType<Video>()
|
||||||
|
@ -743,7 +743,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
public Task RefreshMetadata(CancellationToken cancellationToken)
|
public Task RefreshMetadata(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService()), cancellationToken);
|
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1396,7 +1396,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public virtual Task ChangedExternally()
|
public virtual Task ChangedExternally()
|
||||||
{
|
{
|
||||||
ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions());
|
ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(FileSystem));
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1613,7 +1613,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
var newImagePaths = images.Select(i => i.FullName).ToList();
|
var newImagePaths = images.Select(i => i.FullName).ToList();
|
||||||
|
|
||||||
var deleted = existingImages
|
var deleted = existingImages
|
||||||
.Where(i => !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !File.Exists(i.Path))
|
.Where(i => !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !FileSystem.FileExists(i.Path))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
ImageInfos = ImageInfos.Except(deleted).ToList();
|
ImageInfos = ImageInfos.Except(deleted).ToList();
|
||||||
|
|
|
@ -371,7 +371,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
|
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService()));
|
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(FileSystem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -693,7 +693,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
|
||||||
private bool IsPathOffline(string path)
|
private bool IsPathOffline(string path)
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (FileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
// Depending on whether the path is local or unc, it may return either null or '\' at the top
|
// Depending on whether the path is local or unc, it may return either null or '\' at the top
|
||||||
while (!string.IsNullOrEmpty(path) && path.Length > 1)
|
while (!string.IsNullOrEmpty(path) && path.Length > 1)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(path))
|
if (FileSystem.DirectoryExists(path))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,24 +177,24 @@ namespace MediaBrowser.Controller.Entities
|
||||||
var oldConfigurationDirectory = ConfigurationDirectoryPath;
|
var oldConfigurationDirectory = ConfigurationDirectoryPath;
|
||||||
|
|
||||||
// Exceptions will be thrown if these paths already exist
|
// Exceptions will be thrown if these paths already exist
|
||||||
if (Directory.Exists(newConfigDirectory))
|
if (FileSystem.DirectoryExists(newConfigDirectory))
|
||||||
{
|
{
|
||||||
FileSystem.DeleteDirectory(newConfigDirectory, true);
|
FileSystem.DeleteDirectory(newConfigDirectory, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Directory.Exists(oldConfigurationDirectory))
|
if (FileSystem.DirectoryExists(oldConfigurationDirectory))
|
||||||
{
|
{
|
||||||
Directory.Move(oldConfigurationDirectory, newConfigDirectory);
|
FileSystem.MoveDirectory(oldConfigurationDirectory, newConfigDirectory);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(newConfigDirectory);
|
FileSystem.CreateDirectory(newConfigDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Name = newName;
|
Name = newName;
|
||||||
|
|
||||||
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService())
|
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem))
|
||||||
{
|
{
|
||||||
ReplaceAllMetadata = true,
|
ReplaceAllMetadata = true,
|
||||||
ImageRefreshMode = ImageRefreshMode.FullRefresh,
|
ImageRefreshMode = ImageRefreshMode.FullRefresh,
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
<AssemblyName>MediaBrowser.Controller</AssemblyName>
|
<AssemblyName>MediaBrowser.Controller</AssemblyName>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<ProductVersion>10.0.0</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
|
<ReleaseVersion>
|
||||||
|
</ReleaseVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
|
@ -33,7 +32,6 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||||
|
@ -45,16 +43,11 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Interfaces.IO">
|
<Reference Include="Interfaces.IO">
|
||||||
<HintPath>..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll</HintPath>
|
<HintPath>..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MoreLinq, Version=1.1.18418.0, Culture=neutral, PublicKeyToken=384d532d7e88985d, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\morelinq.1.1.1\lib\net35\MoreLinq.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
@ -66,6 +59,9 @@
|
||||||
<Reference Include="ServiceStack.Interfaces">
|
<Reference Include="ServiceStack.Interfaces">
|
||||||
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath>
|
<HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="MoreLinq">
|
||||||
|
<HintPath>..\packages\morelinq.1.1.1\lib\net35\MoreLinq.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\SharedVersion.cs">
|
<Compile Include="..\SharedVersion.cs">
|
||||||
|
@ -418,8 +414,6 @@
|
||||||
<Compile Include="Sync\ISyncRepository.cs" />
|
<Compile Include="Sync\ISyncRepository.cs" />
|
||||||
<Compile Include="Sync\SyncedFileInfo.cs" />
|
<Compile Include="Sync\SyncedFileInfo.cs" />
|
||||||
<Compile Include="Sync\SyncedItemProgress.cs" />
|
<Compile Include="Sync\SyncedItemProgress.cs" />
|
||||||
<Compile Include="Themes\IAppThemeManager.cs" />
|
|
||||||
<Compile Include="Themes\InternalThemeImage.cs" />
|
|
||||||
<Compile Include="TV\ITVSeriesManager.cs" />
|
<Compile Include="TV\ITVSeriesManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -4,23 +4,26 @@ using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Providers
|
namespace MediaBrowser.Controller.Providers
|
||||||
{
|
{
|
||||||
public class DirectoryService : IDirectoryService
|
public class DirectoryService : IDirectoryService
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, Dictionary<string,FileSystemInfo>> _cache =
|
private readonly ConcurrentDictionary<string, Dictionary<string,FileSystemInfo>> _cache =
|
||||||
new ConcurrentDictionary<string, Dictionary<string, FileSystemInfo>>(StringComparer.OrdinalIgnoreCase);
|
new ConcurrentDictionary<string, Dictionary<string, FileSystemInfo>>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public DirectoryService(ILogger logger)
|
public DirectoryService(ILogger logger, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectoryService()
|
public DirectoryService(IFileSystem fileSystem)
|
||||||
: this(new NullLogger())
|
: this(new NullLogger(), fileSystem)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +62,7 @@ namespace MediaBrowser.Controller.Providers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
|
// using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
|
||||||
var list = new DirectoryInfo(path).EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
|
var list = _fileSystem.GetFileSystemEntries(path);
|
||||||
.Concat<FileSystemInfo>(new DirectoryInfo(path).EnumerateFiles("*", SearchOption.TopDirectoryOnly));
|
|
||||||
|
|
||||||
// Seeing dupes on some users file system for some reason
|
// Seeing dupes on some users file system for some reason
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Providers
|
namespace MediaBrowser.Controller.Providers
|
||||||
{
|
{
|
||||||
|
@ -15,8 +16,8 @@ namespace MediaBrowser.Controller.Providers
|
||||||
|
|
||||||
public bool ForceSave { get; set; }
|
public bool ForceSave { get; set; }
|
||||||
|
|
||||||
public MetadataRefreshOptions()
|
public MetadataRefreshOptions(IFileSystem fileSystem)
|
||||||
: this(new DirectoryService())
|
: this(new DirectoryService(fileSystem))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
using MediaBrowser.Model.Themes;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Themes
|
|
||||||
{
|
|
||||||
public interface IAppThemeManager
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the themes.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="applicationName">Name of the application.</param>
|
|
||||||
/// <returns>IEnumerable{AppThemeInfo}.</returns>
|
|
||||||
IEnumerable<AppThemeInfo> GetThemes(string applicationName);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the theme.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="applicationName">Name of the application.</param>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <returns>AppTheme.</returns>
|
|
||||||
AppTheme GetTheme(string applicationName, string name);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Saves the theme.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="theme">The theme.</param>
|
|
||||||
void SaveTheme(AppTheme theme);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the image image information.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="applicationName">Name of the application.</param>
|
|
||||||
/// <param name="themeName">Name of the theme.</param>
|
|
||||||
/// <param name="imageName">Name of the image.</param>
|
|
||||||
/// <returns>InternalThemeImage.</returns>
|
|
||||||
InternalThemeImage GetImageImageInfo(string applicationName, string themeName, string imageName);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Themes
|
|
||||||
{
|
|
||||||
public class InternalThemeImage
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The name.</value>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the cache tag.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The cache tag.</value>
|
|
||||||
public string CacheTag { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the path.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The path.</value>
|
|
||||||
public string Path { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the date modified.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The date modified.</value>
|
|
||||||
public DateTime DateModified { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -279,8 +279,7 @@ namespace MediaBrowser.Dlna
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(path)
|
return _fileSystem.GetFiles(path)
|
||||||
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
|
|
||||||
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
||||||
.Select(i => ParseProfileXmlFile(i.FullName, type))
|
.Select(i => ParseProfileXmlFile(i.FullName, type))
|
||||||
.Where(i => i != null)
|
.Where(i => i != null)
|
||||||
|
@ -342,8 +341,7 @@ namespace MediaBrowser.Dlna
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(path)
|
return _fileSystem.GetFiles(path)
|
||||||
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
|
|
||||||
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
|
||||||
.Select(i => new InternalProfileInfo
|
.Select(i => new InternalProfileInfo
|
||||||
{
|
{
|
||||||
|
@ -385,7 +383,7 @@ namespace MediaBrowser.Dlna
|
||||||
|
|
||||||
if (!fileInfo.Exists || fileInfo.Length != stream.Length)
|
if (!fileInfo.Exists || fileInfo.Length != stream.Length)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(systemProfilesPath);
|
_fileSystem.CreateDirectory(systemProfilesPath);
|
||||||
|
|
||||||
using (var fileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
|
using (var fileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||||
{
|
{
|
||||||
|
@ -396,7 +394,7 @@ namespace MediaBrowser.Dlna
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not necessary, but just to make it easy to find
|
// Not necessary, but just to make it easy to find
|
||||||
Directory.CreateDirectory(UserProfilesPath);
|
_fileSystem.CreateDirectory(UserProfilesPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteProfile(string id)
|
public void DeleteProfile(string id)
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System.Linq;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.LocalMetadata.Savers
|
namespace MediaBrowser.LocalMetadata.Savers
|
||||||
{
|
{
|
||||||
|
@ -130,9 +131,9 @@ namespace MediaBrowser.LocalMetadata.Savers
|
||||||
/// <param name="xml">The XML.</param>
|
/// <param name="xml">The XML.</param>
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <param name="xmlTagsUsed">The XML tags used.</param>
|
/// <param name="xmlTagsUsed">The XML tags used.</param>
|
||||||
public static void Save(StringBuilder xml, string path, List<string> xmlTagsUsed, IServerConfigurationManager config)
|
public static void Save(StringBuilder xml, string path, List<string> xmlTagsUsed, IServerConfigurationManager config, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (fileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
|
var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
|
||||||
xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
|
xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
|
||||||
|
@ -144,7 +145,7 @@ namespace MediaBrowser.LocalMetadata.Savers
|
||||||
//Add the new node to the document.
|
//Add the new node to the document.
|
||||||
xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement);
|
xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
var wasHidden = false;
|
var wasHidden = false;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace MediaBrowser.MediaEncoding.Configuration
|
||||||
&& !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath))
|
&& !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath))
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!Directory.Exists(newPath))
|
if (!_fileSystem.DirectoryExists(newPath))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
.CreateJob(options, IsVideoEncoder, progress, cancellationToken).ConfigureAwait(false);
|
.CreateJob(options, IsVideoEncoder, progress, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
encodingJob.OutputFilePath = GetOutputFilePath(encodingJob);
|
encodingJob.OutputFilePath = GetOutputFilePath(encodingJob);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(encodingJob.OutputFilePath));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(encodingJob.OutputFilePath));
|
||||||
|
|
||||||
encodingJob.ReadInputAtNativeFramerate = options.ReadInputAtNativeFramerate;
|
encodingJob.ReadInputAtNativeFramerate = options.ReadInputAtNativeFramerate;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
Logger.Info(commandLineLogMessage);
|
Logger.Info(commandLineLogMessage);
|
||||||
|
|
||||||
var logFilePath = Path.Combine(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath, "transcode-" + Guid.NewGuid() + ".txt");
|
var logFilePath = Path.Combine(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath, "transcode-" + Guid.NewGuid() + ".txt");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
FileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
||||||
|
|
||||||
// FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
|
// FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
|
||||||
encodingJob.LogFileStream = FileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true);
|
encodingJob.LogFileStream = FileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true);
|
||||||
|
@ -144,7 +144,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
new JobLogger(Logger).StartStreamingLog(encodingJob, process.StandardError.BaseStream, encodingJob.LogFileStream);
|
new JobLogger(Logger).StartStreamingLog(encodingJob, process.StandardError.BaseStream, encodingJob.LogFileStream);
|
||||||
|
|
||||||
// Wait for the file to exist before proceeeding
|
// Wait for the file to exist before proceeeding
|
||||||
while (!File.Exists(encodingJob.OutputFilePath) && !encodingJob.HasExited)
|
while (!FileSystem.FileExists(encodingJob.OutputFilePath) && !encodingJob.HasExited)
|
||||||
{
|
{
|
||||||
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -605,7 +605,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
vf += string.Format(",scale=min(iw\\,{0}):trunc(ow/dar/2)*2", maxWidthParam);
|
vf += string.Format(",scale=min(iw\\,{0}):trunc(ow/dar/2)*2", maxWidthParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(targetDirectory);
|
FileSystem.CreateDirectory(targetDirectory);
|
||||||
var outputPath = Path.Combine(targetDirectory, filenamePrefix + "%05d.jpg");
|
var outputPath = Path.Combine(targetDirectory, filenamePrefix + "%05d.jpg");
|
||||||
|
|
||||||
var args = string.Format("-i {0} -threads 1 -v quiet -vf \"{2}\" -f image2 \"{1}\"", inputArgument, outputPath, vf);
|
var args = string.Format("-i {0} -threads 1 -v quiet -vf \"{2}\" -f image2 \"{1}\"", inputArgument, outputPath, vf);
|
||||||
|
|
|
@ -183,7 +183,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return File.OpenRead(path);
|
return _fileSystem.OpenRead(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Encoding GetEncoding(string charset)
|
private Encoding GetEncoding(string charset)
|
||||||
|
@ -346,7 +346,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!File.Exists(outputPath))
|
if (!_fileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
await ConvertTextSubtitleToSrtInternal(inputPath, inputProtocol, outputPath, cancellationToken).ConfigureAwait(false);
|
await ConvertTextSubtitleToSrtInternal(inputPath, inputProtocol, outputPath, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
throw new ArgumentNullException("outputPath");
|
throw new ArgumentNullException("outputPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
|
|
||||||
var encodingParam = await GetSubtitleFileCharacterSet(inputPath, inputProtocol, cancellationToken).ConfigureAwait(false);
|
var encodingParam = await GetSubtitleFileCharacterSet(inputPath, inputProtocol, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
_logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
_logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
||||||
|
|
||||||
var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-convert-" + Guid.NewGuid() + ".txt");
|
var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-convert-" + Guid.NewGuid() + ".txt");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
||||||
|
|
||||||
var logFileStream = _fileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read,
|
var logFileStream = _fileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read,
|
||||||
true);
|
true);
|
||||||
|
@ -466,7 +466,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
{
|
{
|
||||||
failed = true;
|
failed = true;
|
||||||
|
|
||||||
if (File.Exists(outputPath))
|
if (_fileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -479,7 +479,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!File.Exists(outputPath))
|
else if (!_fileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!File.Exists(outputPath))
|
if (!_fileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
await ExtractTextSubtitleInternal(_mediaEncoder.GetInputArgument(inputFiles, protocol), subtitleStreamIndex,
|
await ExtractTextSubtitleInternal(_mediaEncoder.GetInputArgument(inputFiles, protocol), subtitleStreamIndex,
|
||||||
outputCodec, outputPath, cancellationToken).ConfigureAwait(false);
|
outputCodec, outputPath, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -540,7 +540,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
throw new ArgumentNullException("outputPath");
|
throw new ArgumentNullException("outputPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
|
|
||||||
var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s {2} \"{3}\"", inputPath,
|
var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s {2} \"{3}\"", inputPath,
|
||||||
subtitleStreamIndex, outputCodec, outputPath);
|
subtitleStreamIndex, outputCodec, outputPath);
|
||||||
|
@ -566,7 +566,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
_logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
_logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
||||||
|
|
||||||
var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-extract-" + Guid.NewGuid() + ".txt");
|
var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-extract-" + Guid.NewGuid() + ".txt");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath));
|
||||||
|
|
||||||
var logFileStream = _fileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read,
|
var logFileStream = _fileSystem.GetFileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read,
|
||||||
true);
|
true);
|
||||||
|
@ -635,7 +635,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
_logger.ErrorException("Error deleting extracted subtitle {0}", ex, outputPath);
|
_logger.ErrorException("Error deleting extracted subtitle {0}", ex, outputPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!File.Exists(outputPath))
|
else if (!_fileSystem.FileExists(outputPath))
|
||||||
{
|
{
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -725,7 +725,7 @@ namespace MediaBrowser.Model.Dlna
|
||||||
|
|
||||||
public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context, PlayMethod playMethod)
|
public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context, PlayMethod playMethod)
|
||||||
{
|
{
|
||||||
if (playMethod != PlayMethod.Transcode)
|
if (playMethod != PlayMethod.Transcode && !subtitleStream.IsExternal)
|
||||||
{
|
{
|
||||||
// Look for supported embedded subs
|
// Look for supported embedded subs
|
||||||
foreach (SubtitleProfile profile in subtitleProfiles)
|
foreach (SubtitleProfile profile in subtitleProfiles)
|
||||||
|
@ -749,17 +749,22 @@ namespace MediaBrowser.Model.Dlna
|
||||||
|
|
||||||
// Look for an external profile that matches the stream type (text/graphical)
|
// Look for an external profile that matches the stream type (text/graphical)
|
||||||
foreach (SubtitleProfile profile in subtitleProfiles)
|
foreach (SubtitleProfile profile in subtitleProfiles)
|
||||||
{
|
{
|
||||||
bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format);
|
if (profile.Method != SubtitleDeliveryMethod.External)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!profile.SupportsLanguage(subtitleStream.Language))
|
if (!profile.SupportsLanguage(subtitleStream.Language))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.Method == SubtitleDeliveryMethod.External && subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format))
|
if (subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format))
|
||||||
{
|
{
|
||||||
if (subtitleStream.IsTextSubtitleStream || !requiresConversion)
|
bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format);
|
||||||
|
|
||||||
|
if (subtitleStream.IsTextSubtitleStream || !requiresConversion)
|
||||||
{
|
{
|
||||||
if (subtitleStream.SupportsExternalStream)
|
if (subtitleStream.SupportsExternalStream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<FodyPath>..\packages\Fody.1.19.1.0</FodyPath>
|
<FodyPath>..\packages\Fody.1.19.1.0</FodyPath>
|
||||||
<ProductVersion>10.0.0</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
|
<ReleaseVersion>
|
||||||
|
</ReleaseVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -26,7 +26,6 @@
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -35,7 +34,6 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release Mono|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release Mono|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -44,14 +42,10 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
|
||||||
<SignAssembly>false</SignAssembly>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyOriginatorKeyFile>MediaBrowser.Model.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>MediaBrowser.Model.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -408,9 +402,6 @@
|
||||||
<Compile Include="Sync\SyncTarget.cs" />
|
<Compile Include="Sync\SyncTarget.cs" />
|
||||||
<Compile Include="System\LogFile.cs" />
|
<Compile Include="System\LogFile.cs" />
|
||||||
<Compile Include="System\PublicSystemInfo.cs" />
|
<Compile Include="System\PublicSystemInfo.cs" />
|
||||||
<Compile Include="Themes\AppTheme.cs" />
|
|
||||||
<Compile Include="Themes\AppThemeInfo.cs" />
|
|
||||||
<Compile Include="Themes\ThemeImage.cs" />
|
|
||||||
<Compile Include="Updates\CheckForUpdateResult.cs" />
|
<Compile Include="Updates\CheckForUpdateResult.cs" />
|
||||||
<Compile Include="Updates\PackageTargetSystem.cs" />
|
<Compile Include="Updates\PackageTargetSystem.cs" />
|
||||||
<Compile Include="Updates\InstallationInfo.cs" />
|
<Compile Include="Updates\InstallationInfo.cs" />
|
||||||
|
@ -465,7 +456,7 @@
|
||||||
<HintPath>..\packages\PropertyChanged.Fody.1.41.0.0\Lib\NET35\PropertyChanged.dll</HintPath>
|
<HintPath>..\packages\PropertyChanged.Fody.1.41.0.0\Lib\NET35\PropertyChanged.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.XML" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Themes
|
|
||||||
{
|
|
||||||
public class AppTheme
|
|
||||||
{
|
|
||||||
public string AppName { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public Dictionary<string, string> Options { get; set; }
|
|
||||||
|
|
||||||
public List<ThemeImage> Images { get; set; }
|
|
||||||
|
|
||||||
public AppTheme()
|
|
||||||
{
|
|
||||||
Options = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
Images = new List<ThemeImage>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
namespace MediaBrowser.Model.Themes
|
|
||||||
{
|
|
||||||
public class AppThemeInfo
|
|
||||||
{
|
|
||||||
public string AppName { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Themes
|
|
||||||
{
|
|
||||||
public class ThemeImage
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the name.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The name.</value>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the cache tag.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The cache tag.</value>
|
|
||||||
public string CacheTag { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -156,7 +156,7 @@ namespace MediaBrowser.Providers.BoxSets
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(_config.ApplicationPaths, tmdbId, preferredMetadataLanguage);
|
var dataFilePath = GetDataFilePath(_config.ApplicationPaths, tmdbId, preferredMetadataLanguage);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
|
|
||||||
_json.SerializeToFile(mainResult, dataFilePath);
|
_json.SerializeToFile(mainResult, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ namespace MediaBrowser.Providers.ImagesByName
|
||||||
|
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(file));
|
fileSystem.CreateDirectory(Path.GetDirectoryName(file));
|
||||||
|
|
||||||
File.Copy(temp, file, true);
|
fileSystem.CopyFile(temp, file, true);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
// If the file is currently hidden we'll have to remove that or the save will fail
|
// If the file is currently hidden we'll have to remove that or the save will fail
|
||||||
var file = new FileInfo(path);
|
var file = new FileInfo(path);
|
||||||
|
|
|
@ -358,7 +358,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
{
|
{
|
||||||
item.ValidateImages(new DirectoryService(_logger));
|
item.ValidateImages(new DirectoryService(_logger, _fileSystem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var existing = item.GetImageInfo(type, 0);
|
var existing = item.GetImageInfo(type, 0);
|
||||||
if (existing != null && !File.Exists(existing.Path))
|
if (existing != null && !_fileSystem.FileExists(existing.Path))
|
||||||
{
|
{
|
||||||
item.RemoveImage(existing);
|
item.RemoveImage(existing);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -702,7 +702,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
// Manual edit occurred
|
// Manual edit occurred
|
||||||
// Even if save local is off, save locally anyway if the metadata file already exists
|
// Even if save local is off, save locally anyway if the metadata file already exists
|
||||||
if (fileSaver == null || !isEnabledFor || !File.Exists(fileSaver.GetSavePath(item)))
|
if (fileSaver == null || !isEnabledFor || !_fileSystem.FileExists(fileSaver.GetSavePath(item)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
{
|
{
|
||||||
var path = GetAudioImagePath(item);
|
var path = GetAudioImagePath(item);
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!_fileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
var semaphore = GetLock(path);
|
var semaphore = GetLock(path);
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check again in case it was saved while waiting for the lock
|
// Check again in case it was saved while waiting for the lock
|
||||||
if (!File.Exists(path))
|
if (!_fileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
using (var stream = await _mediaEncoder.ExtractAudioImage(item.Path, cancellationToken).ConfigureAwait(false))
|
using (var stream = await _mediaEncoder.ExtractAudioImage(item.Path, cancellationToken).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
|
|
|
@ -148,7 +148,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
|
|
||||||
private void FetchShortcutInfo(Video video)
|
private void FetchShortcutInfo(Video video)
|
||||||
{
|
{
|
||||||
video.ShortcutPath = File.ReadAllText(video.Path);
|
video.ShortcutPath = _fileSystem.ReadAllText(video.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, CancellationToken cancellationToken)
|
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, CancellationToken cancellationToken)
|
||||||
|
|
|
@ -706,7 +706,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
|
|
||||||
// Try to eliminate menus and intros by skipping all files at the front of the list that are less than the minimum size
|
// Try to eliminate menus and intros by skipping all files at the front of the list that are less than the minimum size
|
||||||
// Once we reach a file that is at least the minimum, return all subsequent ones
|
// Once we reach a file that is at least the minimum, return all subsequent ones
|
||||||
var allVobs = new DirectoryInfo(root).EnumerateFiles("*", SearchOption.AllDirectories)
|
var allVobs = _fileSystem.GetFiles(root)
|
||||||
.Where(file => string.Equals(file.Extension, ".vob", StringComparison.OrdinalIgnoreCase))
|
.Where(file => string.Equals(file.Extension, ".vob", StringComparison.OrdinalIgnoreCase))
|
||||||
.OrderBy(i => i.FullName)
|
.OrderBy(i => i.FullName)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var path = FanartMovieImageProvider.GetMoviesDataPath(_config.CommonApplicationPaths);
|
var path = FanartMovieImageProvider.GetMoviesDataPath(_config.CommonApplicationPaths);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var timestampFile = Path.Combine(path, "time.txt");
|
var timestampFile = Path.Combine(path, "time.txt");
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out the last time we queried for updates
|
// Find out the last time we queried for updates
|
||||||
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
||||||
|
|
||||||
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
||||||
|
|
||||||
File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
_fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
||||||
|
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var path = GetFanartJsonPath(id);
|
var path = GetFanartJsonPath(id);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Movies
|
namespace MediaBrowser.Providers.Movies
|
||||||
{
|
{
|
||||||
|
@ -22,14 +23,16 @@ namespace MediaBrowser.Providers.Movies
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
|
|
||||||
public GenericMovieDbInfo(ILogger logger, IJsonSerializer jsonSerializer, ILibraryManager libraryManager)
|
public GenericMovieDbInfo(ILogger logger, IJsonSerializer jsonSerializer, ILibraryManager libraryManager, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MetadataResult<T>> GetMetadata(ItemLookupInfo itemId, CancellationToken cancellationToken)
|
public async Task<MetadataResult<T>> GetMetadata(ItemLookupInfo itemId, CancellationToken cancellationToken)
|
||||||
|
@ -88,7 +91,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
tmdbId = movieInfo.id.ToString(_usCulture);
|
tmdbId = movieInfo.id.ToString(_usCulture);
|
||||||
|
|
||||||
dataFilePath = MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
|
dataFilePath = MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
_jsonSerializer.SerializeToFile(movieInfo, dataFilePath);
|
_jsonSerializer.SerializeToFile(movieInfo, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
public Task<MetadataResult<T>> GetItemMetadata<T>(ItemLookupInfo id, CancellationToken cancellationToken)
|
public Task<MetadataResult<T>> GetItemMetadata<T>(ItemLookupInfo id, CancellationToken cancellationToken)
|
||||||
where T : BaseItem, new()
|
where T : BaseItem, new()
|
||||||
{
|
{
|
||||||
var movieDb = new GenericMovieDbInfo<T>(_logger, _jsonSerializer, _libraryManager);
|
var movieDb = new GenericMovieDbInfo<T>(_logger, _jsonSerializer, _libraryManager, _fileSystem);
|
||||||
|
|
||||||
return movieDb.GetMetadata(id, cancellationToken);
|
return movieDb.GetMetadata(id, cancellationToken);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
|
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
|
|
||||||
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var path = MovieDbProvider.GetMoviesDataPath(_config.CommonApplicationPaths);
|
var path = MovieDbProvider.GetMoviesDataPath(_config.CommonApplicationPaths);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var timestampFile = Path.Combine(path, "time.txt");
|
var timestampFile = Path.Combine(path, "time.txt");
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out the last time we queried tvdb for updates
|
// Find out the last time we queried tvdb for updates
|
||||||
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
||||||
|
|
||||||
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(timestampFile, DateTime.UtcNow.Ticks.ToString(UsCulture), Encoding.UTF8);
|
_fileSystem.WriteAllText(timestampFile, DateTime.UtcNow.Ticks.ToString(UsCulture), Encoding.UTF8);
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
var path = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId);
|
var path = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
using (var response = await _httpClient.Get(new HttpRequestOptions
|
using (var response = await _httpClient.Get(new HttpRequestOptions
|
||||||
{
|
{
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
||||||
{
|
{
|
||||||
|
|
|
@ -433,7 +433,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
var xmlPath = GetArtistXmlPath(_config.ApplicationPaths, musicBrainzId);
|
var xmlPath = GetArtistXmlPath(_config.ApplicationPaths, musicBrainzId);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(xmlPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(xmlPath));
|
||||||
|
|
||||||
using (var response = await _httpClient.Get(new HttpRequestOptions
|
using (var response = await _httpClient.Get(new HttpRequestOptions
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
var path = FanartArtistProvider.GetArtistDataPath(_config.CommonApplicationPaths);
|
var path = FanartArtistProvider.GetArtistDataPath(_config.CommonApplicationPaths);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var timestampFile = Path.Combine(path, "time.txt");
|
var timestampFile = Path.Combine(path, "time.txt");
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out the last time we queried for updates
|
// Find out the last time we queried for updates
|
||||||
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
||||||
|
|
||||||
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace MediaBrowser.Providers.Music
|
||||||
|
|
||||||
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
||||||
|
|
||||||
File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
_fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
||||||
|
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ namespace MediaBrowser.Providers.People
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
}).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
|
|
||||||
using (var fs = _fileSystem.GetFileStream(dataFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
using (var fs = _fileSystem.GetFileStream(dataFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
|
||||||
{
|
{
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace MediaBrowser.Providers.Subtitles
|
||||||
_monitor.ReportFileSystemChangeComplete(path, false);
|
_monitor.ReportFileSystemChangeComplete(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _libraryManager.GetItemById(itemId).RefreshMetadata(new MetadataRefreshOptions(new DirectoryService())
|
return _libraryManager.GetItemById(itemId).RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
||||||
{
|
{
|
||||||
ImageRefreshMode = ImageRefreshMode.ValidationOnly,
|
ImageRefreshMode = ImageRefreshMode.ValidationOnly,
|
||||||
MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
|
MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
if (hasNewSeasons)
|
if (hasNewSeasons)
|
||||||
{
|
{
|
||||||
var directoryService = new DirectoryService();
|
var directoryService = new DirectoryService(_fileSystem);
|
||||||
|
|
||||||
//await series.RefreshMetadata(new MetadataRefreshOptions(directoryService), cancellationToken).ConfigureAwait(false);
|
//await series.RefreshMetadata(new MetadataRefreshOptions(directoryService), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
await series.AddChild(season, cancellationToken).ConfigureAwait(false);
|
await series.AddChild(season, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
await season.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken).ConfigureAwait(false);
|
await season.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return season;
|
return season;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var path = FanartSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);
|
var path = FanartSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var timestampFile = Path.Combine(path, "time.txt");
|
var timestampFile = Path.Combine(path, "time.txt");
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out the last time we queried for updates
|
// Find out the last time we queried for updates
|
||||||
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
||||||
|
|
||||||
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
||||||
|
|
||||||
File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
_fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
||||||
|
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,7 +309,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var path = GetFanartJsonPath(tvdbId);
|
var path = GetFanartJsonPath(tvdbId);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
{
|
{
|
||||||
foreach (var series in group)
|
foreach (var series in group)
|
||||||
{
|
{
|
||||||
var directoryService = new DirectoryService();
|
var directoryService = new DirectoryService(_fileSystem);
|
||||||
|
|
||||||
await series.RefreshMetadata(new MetadataRefreshOptions(directoryService)
|
await series.RefreshMetadata(new MetadataRefreshOptions(directoryService)
|
||||||
{
|
{
|
||||||
|
@ -413,7 +413,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
await season.AddChild(episode, cancellationToken).ConfigureAwait(false);
|
await season.AddChild(episode, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
await episode.RefreshMetadata(new MetadataRefreshOptions
|
await episode.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
|
||||||
{
|
{
|
||||||
}, cancellationToken).ConfigureAwait(false);
|
}, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(id, seasonNumber, episodeNumber, preferredMetadataLanguage);
|
var dataFilePath = GetDataFilePath(id, seasonNumber, episodeNumber, preferredMetadataLanguage);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(id, seasonNumber, preferredMetadataLanguage);
|
var dataFilePath = GetDataFilePath(id, seasonNumber, preferredMetadataLanguage);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
tmdbId = seriesInfo.id.ToString(_usCulture);
|
tmdbId = seriesInfo.id.ToString(_usCulture);
|
||||||
|
|
||||||
dataFilePath = GetDataFilePath(tmdbId, language);
|
dataFilePath = GetDataFilePath(tmdbId, language);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
_jsonSerializer.SerializeToFile(seriesInfo, dataFilePath);
|
_jsonSerializer.SerializeToFile(seriesInfo, dataFilePath);
|
||||||
|
|
||||||
await EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
|
await EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
|
||||||
|
@ -289,7 +289,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
|
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
|
||||||
|
|
||||||
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var path = TvdbSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);
|
var path = TvdbSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var timestampFile = Path.Combine(path, "time.txt");
|
var timestampFile = Path.Combine(path, "time.txt");
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out the last time we queried tvdb for updates
|
// Find out the last time we queried tvdb for updates
|
||||||
var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
|
||||||
|
|
||||||
string newUpdateTime;
|
string newUpdateTime;
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
await UpdateSeries(listToUpdate, path, nullableUpdateValue, progress, cancellationToken).ConfigureAwait(false);
|
await UpdateSeries(listToUpdate, path, nullableUpdateValue, progress, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
_fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
seriesDataPath = Path.Combine(seriesDataPath, id);
|
seriesDataPath = Path.Combine(seriesDataPath, id);
|
||||||
|
|
||||||
Directory.CreateDirectory(seriesDataPath);
|
_fileSystem.CreateDirectory(seriesDataPath);
|
||||||
|
|
||||||
return TvdbSeriesProvider.Current.DownloadSeriesZip(id, seriesDataPath, lastTvDbUpdateTime, preferredMetadataLanguage, cancellationToken);
|
return TvdbSeriesProvider.Current.DownloadSeriesZip(id, seriesDataPath, lastTvDbUpdateTime, preferredMetadataLanguage, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
if (!string.Equals(downloadLangaugeXmlFile, saveAsLanguageXmlFile, StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(downloadLangaugeXmlFile, saveAsLanguageXmlFile, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
File.Copy(downloadLangaugeXmlFile, saveAsLanguageXmlFile, true);
|
_fileSystem.CopyFile(downloadLangaugeXmlFile, saveAsLanguageXmlFile, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ExtractEpisodes(seriesDataPath, downloadLangaugeXmlFile, lastTvDbUpdateTime).ConfigureAwait(false);
|
await ExtractEpisodes(seriesDataPath, downloadLangaugeXmlFile, lastTvDbUpdateTime).ConfigureAwait(false);
|
||||||
|
@ -268,9 +268,9 @@ namespace MediaBrowser.Providers.TV
|
||||||
{
|
{
|
||||||
var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesId);
|
var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesId);
|
||||||
|
|
||||||
Directory.CreateDirectory(seriesDataPath);
|
_fileSystem.CreateDirectory(seriesDataPath);
|
||||||
|
|
||||||
var files = new DirectoryInfo(seriesDataPath).EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly)
|
var files = _fileSystem.GetFiles(seriesDataPath)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var seriesXmlFilename = preferredMetadataLanguage + ".xml";
|
var seriesXmlFilename = preferredMetadataLanguage + ".xml";
|
||||||
|
@ -1107,7 +1107,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber, episodeNumber));
|
var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber, episodeNumber));
|
||||||
|
|
||||||
// Only save the file if not already there, or if the episode has changed
|
// Only save the file if not already there, or if the episode has changed
|
||||||
if (hasEpisodeChanged || !File.Exists(file))
|
if (hasEpisodeChanged || !_fileSystem.FileExists(file))
|
||||||
{
|
{
|
||||||
using (var writer = XmlWriter.Create(file, new XmlWriterSettings
|
using (var writer = XmlWriter.Create(file, new XmlWriterSettings
|
||||||
{
|
{
|
||||||
|
@ -1124,7 +1124,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", absoluteNumber));
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", absoluteNumber));
|
||||||
|
|
||||||
// Only save the file if not already there, or if the episode has changed
|
// Only save the file if not already there, or if the episode has changed
|
||||||
if (hasEpisodeChanged || !File.Exists(file))
|
if (hasEpisodeChanged || !_fileSystem.FileExists(file))
|
||||||
{
|
{
|
||||||
using (var writer = XmlWriter.Create(file, new XmlWriterSettings
|
using (var writer = XmlWriter.Create(file, new XmlWriterSettings
|
||||||
{
|
{
|
||||||
|
@ -1167,8 +1167,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var file in new DirectoryInfo(path)
|
foreach (var file in _fileSystem.GetFiles(path, true)
|
||||||
.EnumerateFiles("*.xml", SearchOption.AllDirectories)
|
|
||||||
.ToList())
|
.ToList())
|
||||||
{
|
{
|
||||||
_fileSystem.DeleteFile(file.FullName);
|
_fileSystem.DeleteFile(file.FullName);
|
||||||
|
|
|
@ -318,7 +318,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var files = new DirectoryInfo(parentPath).EnumerateFiles("*", SearchOption.TopDirectoryOnly);
|
var files = _fileSystem.GetFiles(parentPath);
|
||||||
|
|
||||||
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
@ -411,7 +411,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||||
{
|
{
|
||||||
_logger.Debug("Creating directory {0}", path);
|
_logger.Debug("Creating directory {0}", path);
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
fileInfo = new DirectoryInfo(path);
|
fileInfo = new DirectoryInfo(path);
|
||||||
|
|
||||||
if (!fileInfo.Exists)
|
if (!fileInfo.Exists)
|
||||||
|
@ -1082,7 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
_jsonSerializer.SerializeToFile(result, path);
|
_jsonSerializer.SerializeToFile(result, path);
|
||||||
}
|
}
|
||||||
|
@ -1462,7 +1462,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||||
options.RequestHeaders[header.Key] = header.Value;
|
options.RequestHeaders[header.Key] = header.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destination));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(destination));
|
||||||
|
|
||||||
// Determine output extension
|
// Determine output extension
|
||||||
var response = await _httpClient.GetTempFileResponse(options).ConfigureAwait(false);
|
var response = await _httpClient.GetTempFileResponse(options).ConfigureAwait(false);
|
||||||
|
@ -1500,7 +1500,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||||
throw new ApplicationException("Unexpected response type encountered: " + response.ContentType);
|
throw new ApplicationException("Unexpected response type encountered: " + response.ContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.Copy(response.TempFilePath, destination, true);
|
_fileSystem.CopyFile(response.TempFilePath, destination, true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace MediaBrowser.Server.Implementations.Collections
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
var collection = new BoxSet
|
var collection = new BoxSet
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace MediaBrowser.Server.Implementations.Collections
|
||||||
{
|
{
|
||||||
var path = Path.Combine(_appPaths.DataPath, "collections");
|
var path = Path.Combine(_appPaths.DataPath, "collections");
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
return new ManualCollectionsFolder
|
return new ManualCollectionsFolder
|
||||||
{
|
{
|
||||||
|
|
|
@ -198,7 +198,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
||||||
&& !string.Equals(Configuration.ItemsByNamePath ?? string.Empty, newPath))
|
&& !string.Equals(Configuration.ItemsByNamePath ?? string.Empty, newPath))
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!Directory.Exists(newPath))
|
if (!_fileSystem.DirectoryExists(newPath))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
||||||
&& !string.Equals(Configuration.MetadataPath ?? string.Empty, newPath))
|
&& !string.Equals(Configuration.MetadataPath ?? string.Empty, newPath))
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!Directory.Exists(newPath))
|
if (!_fileSystem.DirectoryExists(newPath))
|
||||||
{
|
{
|
||||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
File.WriteAllText(path, address, Encoding.UTF8);
|
_fileSystem.WriteAllText(path, address, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var endpoint = File.ReadAllText(path, Encoding.UTF8);
|
var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8);
|
||||||
|
|
||||||
if (IsValid(endpoint))
|
if (IsValid(endpoint))
|
||||||
{
|
{
|
||||||
|
|
|
@ -315,7 +315,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
var json = _json.SerializeToString(_data);
|
var json = _json.SerializeToString(_data);
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
|
|
||||||
lock (_dataFileLock)
|
lock (_dataFileLock)
|
||||||
{
|
{
|
||||||
File.WriteAllText(path, encrypted, Encoding.UTF8);
|
_fileSystem.WriteAllText(path, encrypted, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -340,7 +340,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
{
|
{
|
||||||
lock (_dataFileLock)
|
lock (_dataFileLock)
|
||||||
{
|
{
|
||||||
var encrypted = File.ReadAllText(path, Encoding.UTF8);
|
var encrypted = _fileSystem.ReadAllText(path, Encoding.UTF8);
|
||||||
|
|
||||||
var json = _encryption.DecryptString(encrypted);
|
var json = _encryption.DecryptString(encrypted);
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.Devices
|
||||||
{
|
{
|
||||||
var path = Path.Combine(_appPaths.DataPath, "camerauploads");
|
var path = Path.Combine(_appPaths.DataPath, "camerauploads");
|
||||||
|
|
||||||
Directory.CreateDirectory(path);
|
_fileSystem.CreateDirectory(path);
|
||||||
|
|
||||||
return new CameraUploadsFolder
|
return new CameraUploadsFolder
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.Devices
|
||||||
|
|
||||||
_libraryMonitor.ReportFileSystemChangeBeginning(path);
|
_libraryMonitor.ReportFileSystemChangeBeginning(path);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.Devices
|
||||||
public Task SaveDevice(DeviceInfo device)
|
public Task SaveDevice(DeviceInfo device)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(GetDevicePath(device.Id), "device.json");
|
var path = Path.Combine(GetDevicePath(device.Id), "device.json");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_syncLock)
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
|
@ -178,7 +178,7 @@ namespace MediaBrowser.Server.Implementations.Devices
|
||||||
public void AddCameraUpload(string deviceId, LocalFileInfo file)
|
public void AddCameraUpload(string deviceId, LocalFileInfo file)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json");
|
var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
lock (_syncLock)
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
|
||||||
{
|
{
|
||||||
var dataPath = Path.Combine(_appPaths.DataPath, "remotenotifications.json");
|
var dataPath = Path.Combine(_appPaths.DataPath, "remotenotifications.json");
|
||||||
|
|
||||||
var lastRunTime = File.Exists(dataPath) ? _fileSystem.GetLastWriteTimeUtc(dataPath) : DateTime.MinValue;
|
var lastRunTime = _fileSystem.FileExists(dataPath) ? _fileSystem.GetLastWriteTimeUtc(dataPath) : DateTime.MinValue;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
|
||||||
{
|
{
|
||||||
var notifications = _json.DeserializeFromStream<RemoteNotification[]>(stream);
|
var notifications = _json.DeserializeFromStream<RemoteNotification[]>(stream);
|
||||||
|
|
||||||
File.WriteAllText(dataPath, string.Empty);
|
_fileSystem.WriteAllText(dataPath, string.Empty);
|
||||||
|
|
||||||
await CreateNotifications(notifications, lastRunTime).ConfigureAwait(false);
|
await CreateNotifications(notifications, lastRunTime).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
_logger.Info("Sorting file {0} to new path {1}", sourcePath, newPath);
|
_logger.Info("Sorting file {0} to new path {1}", sourcePath, newPath);
|
||||||
result.TargetPath = newPath;
|
result.TargetPath = newPath;
|
||||||
|
|
||||||
var fileExists = File.Exists(result.TargetPath);
|
var fileExists = _fileSystem.FileExists(result.TargetPath);
|
||||||
var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber);
|
var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber);
|
||||||
|
|
||||||
if (!overwriteExisting)
|
if (!overwriteExisting)
|
||||||
|
@ -272,7 +272,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
|
|
||||||
var destination = Path.Combine(directory, filename);
|
var destination = Path.Combine(directory, filename);
|
||||||
|
|
||||||
File.Move(file, destination);
|
_fileSystem.MoveFile(file, destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,19 +332,19 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
{
|
{
|
||||||
_libraryMonitor.ReportFileSystemChangeBeginning(result.TargetPath);
|
_libraryMonitor.ReportFileSystemChangeBeginning(result.TargetPath);
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(result.TargetPath));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(result.TargetPath));
|
||||||
|
|
||||||
var targetAlreadyExists = File.Exists(result.TargetPath);
|
var targetAlreadyExists = _fileSystem.FileExists(result.TargetPath);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (targetAlreadyExists || options.CopyOriginalFile)
|
if (targetAlreadyExists || options.CopyOriginalFile)
|
||||||
{
|
{
|
||||||
File.Copy(result.OriginalPath, result.TargetPath, true);
|
_fileSystem.CopyFile(result.OriginalPath, result.TargetPath, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Move(result.OriginalPath, result.TargetPath);
|
_fileSystem.MoveFile(result.OriginalPath, result.TargetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Status = FileSortingStatus.Success;
|
result.Status = FileSortingStatus.Success;
|
||||||
|
|
|
@ -132,8 +132,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new DirectoryInfo(path)
|
return _fileSystem.GetFiles(path, true)
|
||||||
.EnumerateFiles("*", SearchOption.AllDirectories)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -151,8 +150,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
/// <param name="extensions">The extensions.</param>
|
/// <param name="extensions">The extensions.</param>
|
||||||
private void DeleteLeftOverFiles(string path, IEnumerable<string> extensions)
|
private void DeleteLeftOverFiles(string path, IEnumerable<string> extensions)
|
||||||
{
|
{
|
||||||
var eligibleFiles = new DirectoryInfo(path)
|
var eligibleFiles = _fileSystem.GetFiles(path, true)
|
||||||
.EnumerateFiles("*", SearchOption.AllDirectories)
|
|
||||||
.Where(i => extensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
.Where(i => extensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
@ -189,7 +187,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.Debug("Deleting empty directory {0}", path);
|
_logger.Debug("Deleting empty directory {0}", path);
|
||||||
Directory.Delete(path);
|
_fileSystem.DeleteDirectory(path);
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException) { }
|
catch (UnauthorizedAccessException) { }
|
||||||
catch (DirectoryNotFoundException) { }
|
catch (DirectoryNotFoundException) { }
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue