From 14de062681026157c6917779a51af6fb7046cec2 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 13 Sep 2015 17:32:02 -0400 Subject: update file system methods --- .../IO/CommonFileSystem.cs | 60 ++++++++++++++-------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs') diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index e9ef84663..5951dbb31 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -4,6 +4,8 @@ using MediaBrowser.Model.Logging; using System; using System.IO; using System.Text; +using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Common.Implementations.IO { @@ -75,7 +77,7 @@ namespace MediaBrowser.Common.Implementations.IO if (string.Equals(Path.GetExtension(filename), ".mblink", StringComparison.OrdinalIgnoreCase)) { - var path = File.ReadAllText(filename); + var path = ReadAllText(filename); return NormalizePath(path); } @@ -105,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO throw new ArgumentNullException("target"); } - File.WriteAllText(shortcutPath, target); + _fileSystem.WriteAllText(shortcutPath, target); } /// @@ -230,7 +232,7 @@ namespace MediaBrowser.Common.Implementations.IO /// The share. /// if set to true [is asynchronous]. /// FileStream. - 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) { @@ -264,11 +266,11 @@ namespace MediaBrowser.Common.Implementations.IO RemoveHiddenAttribute(file1); RemoveHiddenAttribute(file2); - File.Copy(file1, temp1, true); - File.Copy(file2, temp2, true); + CopyFile(file1, temp1, true); + CopyFile(file2, temp2, true); - File.Copy(temp1, file2, true); - File.Copy(temp2, file1, true); + CopyFile(temp1, file2, true); + CopyFile(temp2, file1, true); DeleteFile(temp1); DeleteFile(temp2); @@ -410,24 +412,42 @@ namespace MediaBrowser.Common.Implementations.IO //return Path.IsPathRooted(path); } - public void DeleteFile(string path, bool sendToRecycleBin) - { - File.Delete(path); - } - - public void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin) - { - Directory.Delete(path, recursive); - } - public void DeleteFile(string path) { - DeleteFile(path, false); + File.Delete(path); } 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 GetDirectories(string path, bool recursive = false) + { + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + + return new DirectoryInfo (path).EnumerateDirectories("*", searchOption); + } + + public IEnumerable GetFiles(string path, bool recursive = false) + { + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + + return new DirectoryInfo (path).EnumerateFiles("*", searchOption); + } + + public IEnumerable GetFileSystemEntries(string path, bool recursive = false) + { + var directoryInfo = new DirectoryInfo (path); + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + + return directoryInfo.EnumerateDirectories("*", searchOption) + .Concat(directoryInfo.EnumerateFiles("*", searchOption)); + } } } -- cgit v1.2.3 From 8cf45a3e4a5345f704f8acef098b173ec1808251 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 13 Sep 2015 19:07:54 -0400 Subject: add more methods to IFileSystem --- Emby.Drawing/ImageMagick/ImageMagickEncoder.cs | 8 ++-- Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs | 5 ++- MediaBrowser.Api/ItemRefreshService.cs | 5 ++- MediaBrowser.Api/Library/LibraryService.cs | 5 ++- .../Library/LibraryStructureService.cs | 5 ++- MediaBrowser.Api/Subtitles/SubtitleService.cs | 5 ++- .../BaseApplicationHost.cs | 6 +-- .../BaseApplicationPaths.cs | 4 +- .../Configuration/BaseConfigurationManager.cs | 4 +- .../Configuration/ConfigurationHelper.cs | 8 ++-- .../Devices/DeviceId.cs | 2 +- .../IO/CommonFileSystem.cs | 52 +++++++++++++++++++++- .../Logging/NlogManager.cs | 2 +- .../ScheduledTasks/ScheduledTaskWorker.cs | 5 ++- .../ScheduledTasks/TaskManager.cs | 7 ++- .../Security/MBLicenseFile.cs | 10 ++--- .../Serialization/JsonSerializer.cs | 6 ++- .../Updates/InstallationManager.cs | 2 +- MediaBrowser.Common/IO/IFileSystem.cs | 22 +++------ MediaBrowser.Controller/Net/IHttpServer.cs | 5 +++ .../Savers/BoxSetXmlSaver.cs | 7 ++- .../Savers/EpisodeXmlSaver.cs | 8 +++- .../Savers/FolderXmlSaver.cs | 7 ++- .../Savers/GameSystemXmlSaver.cs | 7 ++- MediaBrowser.LocalMetadata/Savers/GameXmlSaver.cs | 7 ++- MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs | 7 ++- .../Savers/PersonXmlSaver.cs | 7 ++- .../Savers/PlaylistXmlSaver.cs | 7 ++- .../Savers/SeriesXmlSaver.cs | 7 ++- .../Configuration/EncodingConfigurationFactory.cs | 17 +++++-- .../MediaBrowser.Model.Portable.csproj | 9 ---- .../MediaBrowser.Model.net35.csproj | 9 ---- MediaBrowser.Providers/TV/DummySeasonProvider.cs | 5 ++- .../TV/MissingEpisodeProvider.cs | 7 ++- MediaBrowser.Providers/TV/SeriesMetadataService.cs | 2 +- MediaBrowser.Providers/TV/SeriesPostScanTask.cs | 7 ++- .../Channels/ChannelManager.cs | 2 +- .../Collections/CollectionManager.cs | 2 +- .../Collections/CollectionsDynamicFolder.cs | 5 ++- .../Configuration/ServerConfigurationManager.cs | 6 ++- .../Connect/ConnectEntryPoint.cs | 5 ++- .../Connect/ConnectManager.cs | 7 ++- .../Devices/CameraUploadsFolder.cs | 5 ++- .../FileOrganization/TvFolderOrganizer.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 9 ++++ .../Library/LibraryManager.cs | 16 +++---- .../Library/MediaSourceManager.cs | 5 ++- .../Library/UserManager.cs | 2 +- .../Library/Validators/PeopleValidator.cs | 7 ++- .../LiveTv/EmbyTV/EmbyTV.cs | 8 ++-- .../LiveTv/EmbyTV/ItemDataProvider.cs | 5 ++- .../LiveTv/EmbyTV/SeriesTimerManager.cs | 5 ++- .../LiveTv/EmbyTV/TimerManager.cs | 5 ++- .../LiveTv/LiveTvManager.cs | 6 +-- .../LiveTv/TunerHosts/M3UTunerHost.cs | 6 ++- .../Localization/Core/core.json | 3 +- .../Localization/LocalizationManager.cs | 2 +- .../Persistence/SqliteItemRepository.cs | 2 +- .../Playlists/ManualPlaylistsFolder.cs | 5 ++- .../Playlists/PlaylistManager.cs | 6 +-- .../ScheduledTasks/ChapterImagesTask.cs | 5 ++- .../ApplicationHost.cs | 17 +++---- .../FFMpeg/FFmpegValidator.cs | 5 ++- .../UnhandledExceptionWriter.cs | 4 +- 64 files changed, 296 insertions(+), 149 deletions(-) (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs') diff --git a/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs b/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs index 1fa93d5fb..2f8577acc 100644 --- a/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs +++ b/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs @@ -191,7 +191,7 @@ namespace Emby.Drawing.ImageMagick { var currentImageSize = new ImageSize(imageWidth, imageHeight); - new UnplayedCountIndicator(_appPaths).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value); + new UnplayedCountIndicator(_appPaths, _fileSystem).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value); } if (options.PercentPlayed > 0) @@ -212,15 +212,15 @@ namespace Emby.Drawing.ImageMagick if (ratio >= 1.4) { - new StripCollageBuilder(_appPaths).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); + new StripCollageBuilder(_appPaths, _fileSystem).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); } else if (ratio >= .9) { - new StripCollageBuilder(_appPaths).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); + new StripCollageBuilder(_appPaths, _fileSystem).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); } else { - new StripCollageBuilder(_appPaths).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); + new StripCollageBuilder(_appPaths, _fileSystem).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text); } } diff --git a/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs b/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs index d63abd2a5..92601313a 100644 --- a/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs +++ b/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs @@ -1,5 +1,6 @@ using ImageMagickSharp; using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Model.Drawing; using System.Globalization; @@ -10,10 +11,12 @@ namespace Emby.Drawing.ImageMagick private const int OffsetFromTopRightCorner = 38; private readonly IApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public UnplayedCountIndicator(IApplicationPaths appPaths) + public UnplayedCountIndicator(IApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count) diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 7eb0b87dd..1e74b3692 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using ServiceStack; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.Api { @@ -37,11 +38,13 @@ namespace MediaBrowser.Api { private readonly ILibraryManager _libraryManager; private readonly IProviderManager _providerManager; + private readonly IFileSystem _fileSystem; - public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager) + public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager, IFileSystem fileSystem) { _libraryManager = libraryManager; _providerManager = providerManager; + _fileSystem = fileSystem; } /// diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 9106d86ff..eb1cd6084 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -27,6 +27,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Api.Library { @@ -282,12 +283,13 @@ namespace MediaBrowser.Api.Library private readonly IChannelManager _channelManager; private readonly ITVSeriesManager _tvManager; private readonly ILibraryMonitor _libraryMonitor; + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. /// public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager, - IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor) + IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem) { _itemRepo = itemRepo; _libraryManager = libraryManager; @@ -301,6 +303,7 @@ namespace MediaBrowser.Api.Library _channelManager = channelManager; _tvManager = tvManager; _libraryMonitor = libraryMonitor; + _fileSystem = fileSystem; } public object Get(GetSimilarItems request) diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index c9baf5c37..c8731637c 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -210,7 +210,10 @@ namespace MediaBrowser.Api.Library { var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection"); - _fileSystem.CreateFile(path); + using (File.Create(path)) + { + + } } } finally diff --git a/MediaBrowser.Api/Subtitles/SubtitleService.cs b/MediaBrowser.Api/Subtitles/SubtitleService.cs index 6cfd07cac..0bfe7354d 100644 --- a/MediaBrowser.Api/Subtitles/SubtitleService.cs +++ b/MediaBrowser.Api/Subtitles/SubtitleService.cs @@ -16,6 +16,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MimeTypes = MediaBrowser.Model.Net.MimeTypes; +using MediaBrowser.Common.IO; namespace MediaBrowser.Api.Subtitles { @@ -127,14 +128,16 @@ namespace MediaBrowser.Api.Subtitles private readonly ISubtitleEncoder _subtitleEncoder; private readonly IMediaSourceManager _mediaSourceManager; private readonly IProviderManager _providerManager; + private readonly IFileSystem _fileSystem; - public SubtitleService(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProviderManager providerManager) + public SubtitleService(ILibraryManager libraryManager, ISubtitleManager subtitleManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProviderManager providerManager, IFileSystem fileSystem) { _libraryManager = libraryManager; _subtitleManager = subtitleManager; _subtitleEncoder = subtitleEncoder; _mediaSourceManager = mediaSourceManager; _providerManager = providerManager; + _fileSystem = fileSystem; } public async Task Get(GetSubtitlePlaylist request) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 181f8e43d..af41635f3 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -321,7 +321,7 @@ namespace MediaBrowser.Common.Implementations protected virtual IJsonSerializer CreateJsonSerializer() { - return new JsonSerializer(); + return new JsonSerializer(FileSystemManager); } private void SetHttpLimit() @@ -450,7 +450,7 @@ namespace MediaBrowser.Common.Implementations RegisterSingleInstance(ApplicationPaths); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger, FileSystemManager); RegisterSingleInstance(JsonSerializer); RegisterSingleInstance(XmlSerializer); @@ -651,7 +651,7 @@ namespace MediaBrowser.Common.Implementations { try { - return Assembly.Load(FileSystemManager.ReadAllBytes((file))); + return Assembly.Load(File.ReadAllBytes((file))); } catch (Exception ex) { diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index f76359d30..9ba2effd3 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations { _dataDirectory = Path.Combine(ProgramDataPath, "data"); - FileSystem.CreateDirectory(_dataDirectory); + Directory.CreateDirectory(_dataDirectory); } return _dataDirectory; @@ -152,7 +152,7 @@ namespace MediaBrowser.Common.Implementations { _cachePath = Path.Combine(ProgramDataPath, "cache"); - FileSystem.CreateDirectory(_cachePath); + Directory.CreateDirectory(_cachePath); } return _cachePath; diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 1e9d4c97c..1b9146644 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.Configuration { var path = CommonApplicationPaths.SystemConfigurationFilePath; - FileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); lock (_configurationSyncLock) { @@ -276,7 +276,7 @@ namespace MediaBrowser.Common.Implementations.Configuration _configurations.AddOrUpdate(key, configuration, (k, v) => configuration); var path = GetConfigurationFile(key); - FileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); lock (_configurationSyncLock) { diff --git a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs index 6af59bb6b..276da58d4 100644 --- a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs +++ b/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Common.Implementations.Configuration /// The path. /// The XML serializer. /// System.Object. - public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer, IFileSystem fileSystem) + public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer) { object configuration; @@ -28,7 +28,7 @@ namespace MediaBrowser.Common.Implementations.Configuration // Use try/catch to avoid the extra file system lookup using File.Exists try { - buffer = fileSystem.ReadAllBytes(path); + buffer = File.ReadAllBytes(path); configuration = xmlSerializer.DeserializeFromBytes(type, buffer); } @@ -47,10 +47,10 @@ namespace MediaBrowser.Common.Implementations.Configuration // If the file didn't exist before, or if something has changed, re-save if (buffer == null || !buffer.SequenceEqual(newBytes)) { - fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); // Save it after load in case we got new items - fileSystem.WriteAllBytes(path, newBytes); + File.WriteAllBytes(path, newBytes); } return configuration; diff --git a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs b/MediaBrowser.Common.Implementations/Devices/DeviceId.cs index 02edc493a..39f11fabf 100644 --- a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs +++ b/MediaBrowser.Common.Implementations/Devices/DeviceId.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Common.Implementations.Devices { lock (_syncLock) { - var value = _fileSystem.ReadAllText(CachePath, Encoding.UTF8); + var value = File.ReadAllText(CachePath, Encoding.UTF8); Guid guid; if (Guid.TryParse(value, out guid)) diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index 5951dbb31..2dd2575ad 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -107,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO throw new ArgumentNullException("target"); } - _fileSystem.WriteAllText(shortcutPath, target); + File.WriteAllText(shortcutPath, target); } /// @@ -449,5 +449,55 @@ namespace MediaBrowser.Common.Implementations.IO return directoryInfo.EnumerateDirectories("*", searchOption) .Concat(directoryInfo.EnumerateFiles("*", searchOption)); } + + public Stream OpenRead(string path) + { + return File.OpenRead(path); + } + + public void CopyFile(string source, string target, bool overwrite) + { + File.Copy(source, target, overwrite); + } + + public void MoveFile(string source, string target) + { + File.Move(source, target); + } + + public void MoveDirectory(string source, string target) + { + Directory.Move(source, target); + } + + public bool DirectoryExists(string path) + { + return Directory.Exists(path); + } + + public bool FileExists(string path) + { + return File.Exists(path); + } + + public string ReadAllText(string path) + { + return File.ReadAllText(path); + } + + public void WriteAllText(string path, string text, Encoding encoding) + { + File.WriteAllText(path, text, encoding); + } + + public void WriteAllText(string path, string text) + { + File.WriteAllText(path, text); + } + + public string ReadAllText(string path, Encoding encoding) + { + return File.ReadAllText(path, encoding); + } } } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index 239ea03cd..391e7c212 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Logging { LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(LogFilePath)); + Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); AddFileTarget(LogFilePath, level); diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 08c117220..906184c75 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -12,6 +12,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.ScheduledTasks { @@ -51,6 +52,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// /// The task manager. private ITaskManager TaskManager { get; set; } + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. @@ -71,7 +73,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// or /// logger /// - public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger) + public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { if (scheduledTask == null) { @@ -99,6 +101,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks TaskManager = taskManager; JsonSerializer = jsonSerializer; Logger = logger; + _fileSystem = fileSystem; ReloadTriggerEvents(true); } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index 7034113d7..9419bdf22 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -10,6 +10,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.ScheduledTasks { @@ -50,6 +51,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// /// The logger. private ILogger Logger { get; set; } + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. @@ -58,11 +60,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// The json serializer. /// The logger. /// kernel - public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger) + public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { ApplicationPaths = applicationPaths; JsonSerializer = jsonSerializer; Logger = logger; + _fileSystem = fileSystem; ScheduledTasks = new IScheduledTaskWorker[] { }; } @@ -175,7 +178,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks var myTasks = ScheduledTasks.ToList(); var list = tasks.ToList(); - myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger))); + myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem))); ScheduledTasks = myTasks.ToArray(); } diff --git a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs index e5cf5856e..79e558794 100644 --- a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs +++ b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs @@ -99,15 +99,15 @@ namespace MediaBrowser.Common.Implementations.Security { try { - contents = _fileSystem.ReadAllLines(licenseFile); + contents = File.ReadAllLines(licenseFile); } catch (DirectoryNotFoundException) { - (_fileSystem.CreateFile(licenseFile)).Close(); + (File.Create(licenseFile)).Close(); } catch (FileNotFoundException) { - (_fileSystem.CreateFile(licenseFile)).Close(); + (File.Create(licenseFile)).Close(); } } if (contents != null && contents.Length > 0) @@ -150,8 +150,8 @@ namespace MediaBrowser.Common.Implementations.Security } var licenseFile = Filename; - _fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile)); - lock (_fileLock) _fileSystem.WriteAllLines(licenseFile, lines); + Directory.CreateDirectory(Path.GetDirectoryName(licenseFile)); + lock (_fileLock) File.WriteAllLines(licenseFile, lines); } } } diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 80ccd72f7..2c93f0549 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -1,6 +1,7 @@ using MediaBrowser.Model.Serialization; using System; using System.IO; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.Serialization { @@ -9,8 +10,11 @@ namespace MediaBrowser.Common.Implementations.Serialization /// public class JsonSerializer : IJsonSerializer { - public JsonSerializer() + private readonly IFileSystem _fileSystem; + + public JsonSerializer(IFileSystem fileSystem) { + _fileSystem = fileSystem; Configure(); } diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index fee23fd2e..12afdd8d7 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -573,7 +573,7 @@ namespace MediaBrowser.Common.Implementations.Updates //If it is an archive - write out a version file so we know what it is if (isArchive) { - _fileSystem.WriteAllText(target + ".ver", package.versionStr); + File.WriteAllText(target + ".ver", package.versionStr); } } catch (IOException e) diff --git a/MediaBrowser.Common/IO/IFileSystem.cs b/MediaBrowser.Common/IO/IFileSystem.cs index 60ba4c8ae..1feb20dcb 100644 --- a/MediaBrowser.Common/IO/IFileSystem.cs +++ b/MediaBrowser.Common/IO/IFileSystem.cs @@ -150,8 +150,8 @@ namespace MediaBrowser.Common.IO /// The path. /// if set to true [recursive]. void DeleteDirectory(string path, bool recursive); - - IEnumerable GetDirectories(string path, bool recursive = false); + + IEnumerable GetDirectories(string path, bool recursive = false); IEnumerable GetFiles(string path, bool recursive = false); @@ -169,22 +169,12 @@ namespace MediaBrowser.Common.IO bool FileExists(string path); - string ReadAllText(string path, Encoding encoding); - string ReadAllText(string path); - byte[] ReadAllBytes(string path); - - void WriteAllBytes(string path, byte[] bytes); - - void WriteAllText(string path, string text, Encoding encoding); - - void WriteAllText(string path, string text); - - void CreateFile(string path); - - void WriteAllLines(string path, string[] lines); + void WriteAllText(string path, string text); + + void WriteAllText(string path, string text, Encoding encoding); - string[] ReadAllLines(string path); + string ReadAllText(string path, Encoding encoding); } } diff --git a/MediaBrowser.Controller/Net/IHttpServer.cs b/MediaBrowser.Controller/Net/IHttpServer.cs index 37142af19..91da5fab2 100644 --- a/MediaBrowser.Controller/Net/IHttpServer.cs +++ b/MediaBrowser.Controller/Net/IHttpServer.cs @@ -53,5 +53,10 @@ namespace MediaBrowser.Controller.Net /// Inits this instance. /// void Init(IEnumerable services); + + /// + /// If set, all requests will respond with this message + /// + string GlobalResponse { get; set; } } } \ No newline at end of file diff --git a/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs index e6ae84169..a2180439e 100644 --- a/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -21,11 +22,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public BoxSetXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public BoxSetXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -62,7 +65,7 @@ namespace MediaBrowser.LocalMetadata.Savers var xmlFilePath = GetSavePath(item); - XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config); + XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/EpisodeXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/EpisodeXmlSaver.cs index 96d95d40b..284f33de9 100644 --- a/MediaBrowser.LocalMetadata/Savers/EpisodeXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/EpisodeXmlSaver.cs @@ -9,6 +9,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -19,12 +20,14 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private IFileSystem _fileSystem; - public EpisodeXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager) + public EpisodeXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _itemRepository = itemRepository; _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -143,7 +146,8 @@ namespace MediaBrowser.LocalMetadata.Savers "DVD_episodenumber", "DVD_season", "absolute_number" - }, _config); + + }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/FolderXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/FolderXmlSaver.cs index ac56f0864..655d41255 100644 --- a/MediaBrowser.LocalMetadata/Savers/FolderXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/FolderXmlSaver.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -24,11 +25,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public FolderXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public FolderXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -76,7 +79,7 @@ namespace MediaBrowser.LocalMetadata.Savers var xmlFilePath = GetSavePath(item); - XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config); + XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/GameSystemXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/GameSystemXmlSaver.cs index 770f1d7f9..c6d21655f 100644 --- a/MediaBrowser.LocalMetadata/Savers/GameSystemXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/GameSystemXmlSaver.cs @@ -6,6 +6,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -21,11 +22,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public GameSystemXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public GameSystemXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -69,7 +72,7 @@ namespace MediaBrowser.LocalMetadata.Savers var xmlFilePath = GetSavePath(item); - XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config); + XmlSaverHelpers.Save(builder, xmlFilePath, new List { }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/GameXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/GameXmlSaver.cs index 26c4ff395..fe5d6b27a 100644 --- a/MediaBrowser.LocalMetadata/Savers/GameXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/GameXmlSaver.cs @@ -8,6 +8,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -26,11 +27,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public GameXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public GameXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -101,7 +104,7 @@ namespace MediaBrowser.LocalMetadata.Savers "GameSystem", "NesBox", "NesBoxRom" - }, _config); + }, _config, _fileSystem); } public string GetSavePath(IHasMetadata item) diff --git a/MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs index a6fba3e9b..46d549a3e 100644 --- a/MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/MovieXmlSaver.cs @@ -9,6 +9,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -20,12 +21,14 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IItemRepository _itemRepository; private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private IFileSystem _fileSystem; - public MovieXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager) + public MovieXmlProvider(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _itemRepository = itemRepository; _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } public string Name @@ -122,7 +125,7 @@ namespace MediaBrowser.LocalMetadata.Savers "Artist", "Album", "TmdbCollectionName" - }, _config); + }, _config, _fileSystem); } public string GetSavePath(IHasMetadata item) diff --git a/MediaBrowser.LocalMetadata/Savers/PersonXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/PersonXmlSaver.cs index 9d943bfa4..d199cb3b8 100644 --- a/MediaBrowser.LocalMetadata/Savers/PersonXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/PersonXmlSaver.cs @@ -6,6 +6,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -24,11 +25,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public PersonXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public PersonXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -75,7 +78,7 @@ namespace MediaBrowser.LocalMetadata.Savers XmlSaverHelpers.Save(builder, xmlFilePath, new List { "PlaceOfBirth" - }, _config); + }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs index 7dfe59b4b..4e047252f 100644 --- a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs @@ -7,6 +7,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -22,11 +23,13 @@ namespace MediaBrowser.LocalMetadata.Savers private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; - public PlaylistXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager) + public PlaylistXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } /// @@ -75,7 +78,7 @@ namespace MediaBrowser.LocalMetadata.Savers "OwnerUserId", "PlaylistMediaType" - }, _config); + }, _config, _fileSystem); } /// diff --git a/MediaBrowser.LocalMetadata/Savers/SeriesXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/SeriesXmlSaver.cs index 44b1cd8d3..8150695e7 100644 --- a/MediaBrowser.LocalMetadata/Savers/SeriesXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/SeriesXmlSaver.cs @@ -9,6 +9,7 @@ using System.IO; using System.Security; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.LocalMetadata.Savers { @@ -16,11 +17,13 @@ namespace MediaBrowser.LocalMetadata.Savers { private readonly IServerConfigurationManager _config; private readonly ILibraryManager _libraryManager; + private IFileSystem _fileSystem; - public SeriesXmlProvider(IServerConfigurationManager config, ILibraryManager libraryManager) + public SeriesXmlProvider(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _libraryManager = libraryManager; + _fileSystem = fileSystem; } public string Name @@ -134,7 +137,7 @@ namespace MediaBrowser.LocalMetadata.Savers // Deprecated. No longer saving in this field. "AnimeSeriesIndex" - }, _config); + }, _config, _fileSystem); } /// diff --git a/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs index 1cba14c45..81f2a75ff 100644 --- a/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs +++ b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs @@ -2,26 +2,37 @@ using MediaBrowser.Model.Configuration; using System.Collections.Generic; using System.IO; +using MediaBrowser.Common.IO; namespace MediaBrowser.MediaEncoding.Configuration { public class EncodingConfigurationFactory : IConfigurationFactory { + private readonly IFileSystem _fileSystem; + + public EncodingConfigurationFactory(IFileSystem fileSystem) + { + _fileSystem = fileSystem; + } + public IEnumerable GetConfigurations() { return new[] { - new EncodingConfigurationStore() + new EncodingConfigurationStore(_fileSystem) }; } } public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration { - public EncodingConfigurationStore() + private readonly IFileSystem _fileSystem; + + public EncodingConfigurationStore(IFileSystem fileSystem) { ConfigurationType = typeof(EncodingOptions); Key = "encoding"; + _fileSystem = fileSystem; } public void Validate(object oldConfig, object newConfig) @@ -35,7 +46,7 @@ namespace MediaBrowser.MediaEncoding.Configuration && !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath)) { // Validate - if (!_fileSystem.DirectoryExists(newPath)) + if (!_fileSystem.DirectoryExists(newPath)) { throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath)); } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 7d813e903..40e532b79 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -1184,15 +1184,6 @@ Tasks\TaskTriggerInfo.cs - - Themes\AppTheme.cs - - - Themes\AppThemeInfo.cs - - - Themes\ThemeImage.cs - Updates\CheckForUpdateResult.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 8605a0ab3..09a7cde9d 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -1140,15 +1140,6 @@ Tasks\TaskTriggerInfo.cs - - Themes\AppTheme.cs - - - Themes\AppThemeInfo.cs - - - Themes\ThemeImage.cs - Updates\CheckForUpdateResult.cs diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 1bee5d517..c61b4f279 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -10,6 +10,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Providers.TV { @@ -19,15 +20,17 @@ namespace MediaBrowser.Providers.TV private readonly ILogger _logger; private readonly ILocalizationManager _localization; private readonly ILibraryManager _libraryManager; + private readonly IFileSystem _fileSystem; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager) + public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IFileSystem fileSystem) { _config = config; _logger = logger; _localization = localization; _libraryManager = libraryManager; + _fileSystem = fileSystem; } public async Task Run(Series series, CancellationToken cancellationToken) diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index b7cf627c1..1443c524f 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -15,6 +15,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; +using MediaBrowser.Common.IO; namespace MediaBrowser.Providers.TV { @@ -24,15 +25,17 @@ namespace MediaBrowser.Providers.TV private readonly ILogger _logger; private readonly ILibraryManager _libraryManager; private readonly ILocalizationManager _localization; + private readonly IFileSystem _fileSystem; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public MissingEpisodeProvider(ILogger logger, IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization) + public MissingEpisodeProvider(ILogger logger, IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization, IFileSystem fileSystem) { _logger = logger; _config = config; _libraryManager = libraryManager; _localization = localization; + _fileSystem = fileSystem; } public async Task Run(IEnumerable> series, CancellationToken cancellationToken) @@ -395,7 +398,7 @@ namespace MediaBrowser.Providers.TV if (season == null) { - var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager); + var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager, _fileSystem); season = await provider.AddSeason(series, seasonNumber, cancellationToken).ConfigureAwait(false); } diff --git a/MediaBrowser.Providers/TV/SeriesMetadataService.cs b/MediaBrowser.Providers/TV/SeriesMetadataService.cs index 0b2aaa5a0..24da853d3 100644 --- a/MediaBrowser.Providers/TV/SeriesMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeriesMetadataService.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Providers.TV if (refreshOptions.IsPostRecursiveRefresh) { - var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager); + var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager, FileSystem); try { diff --git a/MediaBrowser.Providers/TV/SeriesPostScanTask.cs b/MediaBrowser.Providers/TV/SeriesPostScanTask.cs index 874b5c92d..f7a2dcefe 100644 --- a/MediaBrowser.Providers/TV/SeriesPostScanTask.cs +++ b/MediaBrowser.Providers/TV/SeriesPostScanTask.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Providers.TV { @@ -27,13 +28,15 @@ namespace MediaBrowser.Providers.TV private readonly IServerConfigurationManager _config; private readonly ILogger _logger; private readonly ILocalizationManager _localization; + private readonly IFileSystem _fileSystem; - public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, ILocalizationManager localization) + public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, ILocalizationManager localization, IFileSystem fileSystem) { _libraryManager = libraryManager; _logger = logger; _config = config; _localization = localization; + _fileSystem = fileSystem; } public Task Run(IProgress progress, CancellationToken cancellationToken) @@ -50,7 +53,7 @@ namespace MediaBrowser.Providers.TV var seriesGroups = FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList(); - await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization).Run(seriesGroups, cancellationToken).ConfigureAwait(false); + await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem).Run(seriesGroups, cancellationToken).ConfigureAwait(false); var numComplete = 0; diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index b02b2996f..9edfc0c35 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -448,7 +448,7 @@ namespace MediaBrowser.Server.Implementations.Channels item.Name = channelInfo.Name; } - await item.RefreshMetadata(new MetadataRefreshOptions + await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = isNew diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 3932e4073..b8c23224f 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.Collections await parentFolder.AddChild(collection, CancellationToken.None).ConfigureAwait(false); - await collection.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService()), CancellationToken.None) + await collection.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), CancellationToken.None) .ConfigureAwait(false); if (options.ItemIdList.Count > 0) diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs b/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs index 959c47947..0fc7fb3f6 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionsDynamicFolder.cs @@ -1,16 +1,19 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using System.IO; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Collections { public class CollectionsDynamicFolder : IVirtualFolderCreator { private readonly IApplicationPaths _appPaths; + private IFileSystem _fileSystem; - public CollectionsDynamicFolder(IApplicationPaths appPaths) + public CollectionsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public BasePluginFolder GetFolder() diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 54e53d7c4..050b79db7 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -15,6 +15,7 @@ using MediaBrowser.Model.Serialization; using System; using System.IO; using System.Linq; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Configuration { @@ -23,15 +24,18 @@ namespace MediaBrowser.Server.Implementations.Configuration /// public class ServerConfigurationManager : BaseConfigurationManager, IServerConfigurationManager { + private readonly IFileSystem _fileSystem; + /// /// Initializes a new instance of the class. /// /// The application paths. /// The log manager. /// The XML serializer. - public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer) + public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) : base(applicationPaths, logManager, xmlSerializer) { + _fileSystem = fileSystem; UpdateItemsByNamePath(); UpdateMetadataPath(); } diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs index 86feaee6d..a8900fa5b 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -10,6 +10,7 @@ using System.IO; using System.Net; using System.Text; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Connect { @@ -23,8 +24,9 @@ namespace MediaBrowser.Server.Implementations.Connect private readonly INetworkManager _networkManager; private readonly IApplicationHost _appHost; + private readonly IFileSystem _fileSystem; - public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost) + public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem) { _httpClient = httpClient; _appPaths = appPaths; @@ -32,6 +34,7 @@ namespace MediaBrowser.Server.Implementations.Connect _networkManager = networkManager; _connectManager = connectManager; _appHost = appHost; + _fileSystem = fileSystem; } public void Run() diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index f9aa8814d..aab3a2121 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -23,6 +23,7 @@ using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Connect { @@ -40,6 +41,7 @@ namespace MediaBrowser.Server.Implementations.Connect private readonly IUserManager _userManager; private readonly IProviderManager _providerManager; private readonly ISecurityManager _securityManager; + private readonly IFileSystem _fileSystem; private ConnectData _data = new ConnectData(); @@ -104,7 +106,7 @@ namespace MediaBrowser.Server.Implementations.Connect IEncryptionManager encryption, IHttpClient httpClient, IServerApplicationHost appHost, - IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager, ISecurityManager securityManager) + IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager, ISecurityManager securityManager, IFileSystem fileSystem) { _logger = logger; _appPaths = appPaths; @@ -116,6 +118,7 @@ namespace MediaBrowser.Server.Implementations.Connect _userManager = userManager; _providerManager = providerManager; _securityManager = securityManager; + _fileSystem = fileSystem; _userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated; _config.ConfigurationUpdated += _config_ConfigurationUpdated; @@ -943,7 +946,7 @@ namespace MediaBrowser.Server.Implementations.Connect { await _providerManager.SaveImage(user, imageUrl, _connectImageSemaphore, ImageType.Primary, null, CancellationToken.None).ConfigureAwait(false); - await user.RefreshMetadata(new MetadataRefreshOptions + await user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = true, diff --git a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs index d0058b5ff..15567703d 100644 --- a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs +++ b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using System; using System.IO; using System.Linq; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Devices { @@ -51,10 +52,12 @@ namespace MediaBrowser.Server.Implementations.Devices public class CameraUploadsDynamicFolder : IVirtualFolderCreator { private readonly IApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public CameraUploadsDynamicFolder(IApplicationPaths appPaths) + public CameraUploadsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public BasePluginFolder GetFolder() diff --git a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index 3e7a1d59e..a51e8775e 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -187,7 +187,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization try { _logger.Debug("Deleting empty directory {0}", path); - _fileSystem.DeleteDirectory(path); + _fileSystem.DeleteDirectory(path, false); } catch (UnauthorizedAccessException) { } catch (DirectoryNotFoundException) { } diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 3795f4b15..1885afc61 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -79,6 +79,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer _containerAdapter = new ContainerAdapter(applicationHost); } + public string GlobalResponse { get; set; } + public override void Configure(Container container) { HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath; @@ -336,6 +338,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer return Task.FromResult(true); } + if (!string.IsNullOrWhiteSpace(GlobalResponse)) + { + httpRes.Write(GlobalResponse); + httpRes.ContentType = "text/plain"; + return Task.FromResult(true); + } + var handler = HttpHandlerFactory.GetHandler(httpReq); var remoteIp = httpReq.RemoteIp; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c3ef5366d..8d843e1ca 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -548,7 +548,7 @@ namespace MediaBrowser.Server.Implementations.Library public BaseItem ResolvePath(FileSystemInfo fileInfo, Folder parent = null) { - return ResolvePath(fileInfo, new DirectoryService(_logger), parent); + return ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), parent); } private BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null) @@ -1009,7 +1009,7 @@ namespace MediaBrowser.Server.Implementations.Library // Ensure the location is available. _fileSystem.CreateDirectory(ConfigurationManager.ApplicationPaths.PeoplePath); - return new PeopleValidator(this, _logger, ConfigurationManager).ValidatePeople(cancellationToken, progress); + return new PeopleValidator(this, _logger, ConfigurationManager, _fileSystem).ValidatePeople(cancellationToken, progress); } /// @@ -1064,7 +1064,7 @@ namespace MediaBrowser.Server.Implementations.Library progress.Report(.5); // Start by just validating the children of the root, but go no further - await RootFolder.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(), recursive: false); + await RootFolder.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false); progress.Report(1); @@ -1072,7 +1072,7 @@ namespace MediaBrowser.Server.Implementations.Library await userRoot.RefreshMetadata(cancellationToken).ConfigureAwait(false); - await userRoot.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(), recursive: false).ConfigureAwait(false); + await userRoot.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false); progress.Report(2); var innerProgress = new ActionableProgress(); @@ -1080,7 +1080,7 @@ namespace MediaBrowser.Server.Implementations.Library innerProgress.RegisterAction(pct => progress.Report(2 + pct * .73)); // Now validate the entire media library - await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(), recursive: true).ConfigureAwait(false); + await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: true).ConfigureAwait(false); progress.Report(75); @@ -1702,7 +1702,7 @@ namespace MediaBrowser.Server.Implementations.Library if (refresh) { await item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None).ConfigureAwait(false); - _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions + _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem) { // Not sure why this is necessary but need to figure it out // View images are not getting utilized without this @@ -1790,7 +1790,7 @@ namespace MediaBrowser.Server.Implementations.Library if (refresh) { - _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions + _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem) { // Need to force save to increment DateLastSaved ForceSave = true @@ -1860,7 +1860,7 @@ namespace MediaBrowser.Server.Implementations.Library if (refresh) { - _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions + _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem) { // Need to force save to increment DateLastSaved ForceSave = true diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index d967f8b11..a348c728e 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -15,6 +15,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Library { @@ -24,17 +25,19 @@ namespace MediaBrowser.Server.Implementations.Library private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; private readonly IJsonSerializer _jsonSerializer; + private readonly IFileSystem _fileSystem; private IMediaSourceProvider[] _providers; private readonly ILogger _logger; - public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer) + public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem) { _itemRepo = itemRepo; _userManager = userManager; _libraryManager = libraryManager; _logger = logger; _jsonSerializer = jsonSerializer; + _fileSystem = fileSystem; } public void AddParts(IEnumerable providers) diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 83dcc7fc1..a8fc7b4aa 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -454,7 +454,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task. public Task RefreshUsersMetadata(CancellationToken cancellationToken) { - var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken)).ToList(); + var tasks = Users.Select(user => user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken)).ToList(); return Task.WhenAll(tasks); } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs index a4c43af5d..c6b294e83 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Library.Validators { @@ -29,17 +30,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators private readonly ILogger _logger; private readonly IServerConfigurationManager _config; + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. /// /// The library manager. /// The logger. - public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config) + public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem) { _libraryManager = libraryManager; _logger = logger; _config = config; + _fileSystem = fileSystem; } private bool DownloadMetadata(PersonInfo i, PeopleMetadataOptions options) @@ -121,7 +124,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators validIds.Add(item.Id); - var options = new MetadataRefreshOptions + var options = new MetadataRefreshOptions(_fileSystem) { MetadataRefreshMode = person.Value ? MetadataRefreshMode.Default : MetadataRefreshMode.ValidationOnly, ImageRefreshMode = person.Value ? ImageRefreshMode.Default : ImageRefreshMode.ValidationOnly diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index f2d9ca21d..63c49bcbc 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -71,9 +71,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV _liveTvManager = (LiveTvManager)liveTvManager; _jsonSerializer = jsonSerializer; - _recordingProvider = new ItemDataProvider(jsonSerializer, _logger, Path.Combine(DataPath, "recordings"), (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)); - _seriesTimerProvider = new SeriesTimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers")); - _timerProvider = new TimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "timers")); + _recordingProvider = new ItemDataProvider(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "recordings"), (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)); + _seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers")); + _timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers")); _timerProvider.TimerFired += _timerProvider_TimerFired; } @@ -239,7 +239,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { - _filesystem.DeleteFile(remove.Path); + _fileSystem.DeleteFile(remove.Path); } catch (DirectoryNotFoundException) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs index 9769148a2..2c8917ab4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV { @@ -16,13 +17,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV protected readonly ILogger Logger; private readonly string _dataPath; protected readonly Func EqualityComparer; + private readonly IFileSystem _fileSystem; - public ItemDataProvider(IJsonSerializer jsonSerializer, ILogger logger, string dataPath, Func equalityComparer) + public ItemDataProvider(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, Func equalityComparer) { Logger = logger; _dataPath = dataPath; EqualityComparer = equalityComparer; _jsonSerializer = jsonSerializer; + _fileSystem = fileSystem; } public IReadOnlyList GetAll() diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/SeriesTimerManager.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/SeriesTimerManager.cs index eab278eb4..563658885 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/SeriesTimerManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/SeriesTimerManager.cs @@ -2,13 +2,14 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV { public class SeriesTimerManager : ItemDataProvider { - public SeriesTimerManager(IJsonSerializer jsonSerializer, ILogger logger, string dataPath) - : base(jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) + public SeriesTimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath) + : base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) { } diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs index 3ae38f382..64a5b7339 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Concurrent; using System.Linq; using System.Threading; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV { @@ -16,8 +17,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV public event EventHandler> TimerFired; - public TimerManager(IJsonSerializer jsonSerializer, ILogger logger, string dataPath) - : base(jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) + public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath) + : base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) { } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index d73b144b8..e2c00ea6b 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -580,7 +580,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv item.Name = channelInfo.Name; } - await item.RefreshMetadata(new MetadataRefreshOptions + await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = isNew, ReplaceImages = replaceImages.Distinct().ToList() @@ -659,7 +659,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } } - _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions()); + _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)); return item; } @@ -759,7 +759,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); } - _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions()); + _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)); return item.Id; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index faec569f6..31139b15d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -12,14 +12,18 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts { public class M3UTunerHost : BaseTunerHost, ITunerHost { - public M3UTunerHost(IConfigurationManager config, ILogger logger) + private readonly IFileSystem _fileSystem; + + public M3UTunerHost(IConfigurationManager config, ILogger logger, IFileSystem fileSystem) : base(config, logger) { + _fileSystem = fileSystem; } public override string Type diff --git a/MediaBrowser.Server.Implementations/Localization/Core/core.json b/MediaBrowser.Server.Implementations/Localization/Core/core.json index 4eb66929d..5f11b9436 100644 --- a/MediaBrowser.Server.Implementations/Localization/Core/core.json +++ b/MediaBrowser.Server.Implementations/Localization/Core/core.json @@ -173,5 +173,6 @@ "HeaderProducer": "Producers", "HeaderWriter": "Writers", "HeaderParentalRatings": "Parental Ratings", - "HeaderCommunityRatings": "Community ratings" + "HeaderCommunityRatings": "Community ratings", + "StartupEmbyServerIsLoading": "Emby Server is loading. Please try again shortly." } diff --git a/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs b/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs index 4842fbb24..e776f4311 100644 --- a/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs +++ b/MediaBrowser.Server.Implementations/Localization/LocalizationManager.cs @@ -212,7 +212,7 @@ namespace MediaBrowser.Server.Implementations.Localization /// Dictionary{System.StringParentalRating}. private void LoadRatings(string file) { - var dict = _fileSystem.ReadAllLines(file).Select(i => + var dict = File.ReadAllLines(file).Select(i => { if (!string.IsNullOrWhiteSpace(i)) { diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e2b85743b..bd128a16e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -617,7 +617,7 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Task. public Task SaveCriticReviews(Guid itemId, IEnumerable criticReviews) { - _fileSystem.CreateDirectory(_criticReviewsPath); + Directory.CreateDirectory(_criticReviewsPath); var path = Path.Combine(_criticReviewsPath, itemId + ".json"); diff --git a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs index 4c972d23d..0daef052d 100644 --- a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs +++ b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Playlists; using System.Collections.Generic; using System.IO; using System.Linq; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Playlists { @@ -46,10 +47,12 @@ namespace MediaBrowser.Server.Implementations.Playlists public class PlaylistsDynamicFolder : IVirtualFolderCreator { private readonly IApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public PlaylistsDynamicFolder(IApplicationPaths appPaths) + public PlaylistsDynamicFolder(IApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public BasePluginFolder GetFolder() diff --git a/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs b/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs index 542fa14c5..53f2211d3 100644 --- a/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs +++ b/MediaBrowser.Server.Implementations/Playlists/PlaylistManager.cs @@ -128,7 +128,7 @@ namespace MediaBrowser.Server.Implementations.Playlists await parentFolder.AddChild(playlist, CancellationToken.None).ConfigureAwait(false); - await playlist.RefreshMetadata(new MetadataRefreshOptions { ForceSave = true }, CancellationToken.None) + await playlist.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { ForceSave = true }, CancellationToken.None) .ConfigureAwait(false); if (options.ItemIdList.Count > 0) @@ -196,7 +196,7 @@ namespace MediaBrowser.Server.Implementations.Playlists await playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); - _providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions + _providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(_fileSystem) { ForceSave = true }); @@ -223,7 +223,7 @@ namespace MediaBrowser.Server.Implementations.Playlists await playlist.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); - _providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions + _providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(_fileSystem) { ForceSave = true }); diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs index 4e9d9ab18..f8dc08e26 100644 --- a/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs +++ b/MediaBrowser.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs @@ -11,6 +11,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.ScheduledTasks { @@ -39,6 +40,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks private readonly IApplicationPaths _appPaths; private readonly IEncodingManager _encodingManager; + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. @@ -46,13 +48,14 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks /// The log manager. /// The library manager. /// The item repo. - public ChapterImagesTask(ILogManager logManager, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager) + public ChapterImagesTask(ILogManager logManager, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager, IFileSystem fileSystem) { _logger = logManager.GetLogger(GetType().Name); _libraryManager = libraryManager; _itemRepo = itemRepo; _appPaths = appPaths; _encodingManager = encodingManager; + _fileSystem = fileSystem; } /// diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 5f8e3ee21..ad2cd96b6 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -42,7 +42,6 @@ using MediaBrowser.Controller.Social; using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Subtitles; using MediaBrowser.Controller.Sync; -using MediaBrowser.Controller.Themes; using MediaBrowser.Controller.TV; using MediaBrowser.Dlna; using MediaBrowser.Dlna.ConnectionManager; @@ -87,7 +86,6 @@ using MediaBrowser.Server.Implementations.ServerManager; using MediaBrowser.Server.Implementations.Session; using MediaBrowser.Server.Implementations.Social; using MediaBrowser.Server.Implementations.Sync; -using MediaBrowser.Server.Implementations.Themes; using MediaBrowser.Server.Implementations.TV; using MediaBrowser.Server.Startup.Common.FFMpeg; using MediaBrowser.Server.Startup.Common.Migrations; @@ -124,7 +122,7 @@ namespace MediaBrowser.Server.Startup.Common /// IConfigurationManager. protected override IConfigurationManager GetConfigurationManager() { - return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer); + return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer, FileSystemManager); } /// @@ -314,6 +312,7 @@ namespace MediaBrowser.Server.Startup.Common await base.RunStartupTasks().ConfigureAwait(false); Logger.Info("Core startup complete"); + HttpServer.GlobalResponse = null; Parallel.ForEach(GetExports(), entryPoint => { @@ -434,6 +433,7 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(() => new SearchEngine(LogManager, LibraryManager, UserManager)); HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, "Emby", "web/index.html"); + HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading"); RegisterSingleInstance(HttpServer, false); progress.Report(10); @@ -458,7 +458,7 @@ namespace MediaBrowser.Server.Startup.Common var encryptionManager = new EncryptionManager(); RegisterSingleInstance(encryptionManager); - ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager); + ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager, FileSystemManager); RegisterSingleInstance(ConnectManager); DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, LogManager.GetLogger("DeviceManager"), FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ConfigurationManager, LogManager.GetLogger("DeviceManager"), NetworkManager); @@ -475,15 +475,12 @@ namespace MediaBrowser.Server.Startup.Common ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LogManager.GetLogger("ChannelManager"), ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient); RegisterSingleInstance(ChannelManager); - MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer); + MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager); RegisterSingleInstance(MediaSourceManager); SessionManager = new SessionManager(UserDataManager, LogManager.GetLogger("SessionManager"), UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager); RegisterSingleInstance(SessionManager); - var appThemeManager = new AppThemeManager(ApplicationPaths, FileSystemManager, JsonSerializer, Logger); - RegisterSingleInstance(appThemeManager); - var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LogManager.GetLogger("Dlna"), JsonSerializer, this); RegisterSingleInstance(dlnaManager); @@ -573,7 +570,7 @@ namespace MediaBrowser.Server.Startup.Common { try { - return new ImageMagickEncoder(LogManager.GetLogger("ImageMagick"), ApplicationPaths, HttpClient); + return new ImageMagickEncoder(LogManager.GetLogger("ImageMagick"), ApplicationPaths, HttpClient, FileSystemManager); } catch (Exception ex) { @@ -598,7 +595,7 @@ namespace MediaBrowser.Server.Startup.Common var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment) .GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false); - new FFmpegValidator(Logger, ApplicationPaths).Validate(info); + new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(info); MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs index 384111add..54cd1357a 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Startup.Common.FFMpeg { @@ -13,11 +14,13 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg { private readonly ILogger _logger; private readonly IApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public FFmpegValidator(ILogger logger, IApplicationPaths appPaths) + public FFmpegValidator(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem) { _logger = logger; _appPaths = appPaths; + _fileSystem = fileSystem; } public void Validate(FFMpegInfo info) diff --git a/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs index e08ada2e0..804533b9d 100644 --- a/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs +++ b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs @@ -25,7 +25,7 @@ namespace MediaBrowser.Server.Startup.Common _logManager.Flush(); var path = Path.Combine(_appPaths.LogDirectoryPath, "unhandled_" + Guid.NewGuid() + ".txt"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); var builder = LogHelper.GetLogMessage(ex); @@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Startup.Common Console.WriteLine("UnhandledException"); Console.WriteLine(builder.ToString()); - _fileSystem.WriteAllText(path, builder.ToString()); + File.WriteAllText(path, builder.ToString()); } } } -- cgit v1.2.3 From aff7309a08b01d7eae24d140f55d36898b49d3df Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 18 Sep 2015 13:50:24 -0400 Subject: update ffmpeg with qsv-compatible version --- MediaBrowser.Api/Playback/Dash/MpegDashService.cs | 4 ++-- .../IO/CommonFileSystem.cs | 18 ++++++++++++++++++ MediaBrowser.Common/IO/IFileSystem.cs | 6 ++++++ MediaBrowser.Providers/TV/TvdbSeriesProvider.cs | 4 ++-- .../FileOrganization/TvFolderOrganizer.cs | 4 ++-- .../Library/LibraryManager.cs | 2 +- .../FFMpeg/FFMpegDownloadInfo.cs | 10 +++++----- Nuget/MediaBrowser.Common.Internal.nuspec | 4 ++-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 ++-- 11 files changed, 42 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs') diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs index 886484801..cbee821d2 100644 --- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs @@ -352,9 +352,9 @@ namespace MediaBrowser.Api.Playback.Dash try { - foreach (var subfolder in FileSystem.GetDirectories(folder).ToList()) + foreach (var subfolder in FileSystem.GetDirectoryPaths(folder).ToList()) { - var subfolderName = Path.GetFileNameWithoutExtension(subfolder.FullName); + var subfolderName = Path.GetFileNameWithoutExtension(subfolder); int startNumber; if (int.TryParse(subfolderName, NumberStyles.Any, UsCulture, out startNumber)) { diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index 2dd2575ad..b899e88c2 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -499,5 +499,23 @@ namespace MediaBrowser.Common.Implementations.IO { return File.ReadAllText(path, encoding); } + + public IEnumerable GetDirectoryPaths(string path, bool recursive = false) + { + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + return Directory.EnumerateDirectories(path, "*", searchOption); + } + + public IEnumerable GetFilePaths(string path, bool recursive = false) + { + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + return Directory.EnumerateFiles(path, "*", searchOption); + } + + public IEnumerable GetFileSystemEntryPaths(string path, bool recursive = false) + { + var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; + return Directory.EnumerateFileSystemEntries(path, "*", searchOption); + } } } diff --git a/MediaBrowser.Common/IO/IFileSystem.cs b/MediaBrowser.Common/IO/IFileSystem.cs index 1feb20dcb..ce15ad999 100644 --- a/MediaBrowser.Common/IO/IFileSystem.cs +++ b/MediaBrowser.Common/IO/IFileSystem.cs @@ -176,5 +176,11 @@ namespace MediaBrowser.Common.IO void WriteAllText(string path, string text, Encoding encoding); string ReadAllText(string path, Encoding encoding); + + IEnumerable GetDirectoryPaths(string path, bool recursive = false); + + IEnumerable GetFilePaths(string path, bool recursive = false); + + IEnumerable GetFileSystemEntryPaths(string path, bool recursive = false); } } diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index f2dc65c95..56e9dbd03 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -1167,10 +1167,10 @@ namespace MediaBrowser.Providers.TV { try { - foreach (var file in _fileSystem.GetFiles(path, true) + foreach (var file in _fileSystem.GetFilePaths(path, true) .ToList()) { - _fileSystem.DeleteFile(file.FullName); + _fileSystem.DeleteFile(file); } } catch (DirectoryNotFoundException) diff --git a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index a51e8775e..2867cbecb 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -111,8 +111,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization { try { - return Directory - .EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly) + return _fileSystem + .GetFileSystemEntryPaths(path) .ToList(); } catch (IOException ex) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index a0d2cd0d6..26961c490 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1165,7 +1165,7 @@ namespace MediaBrowser.Server.Implementations.Library /// IEnumerable{VirtualFolderInfo}. private IEnumerable GetView(string path) { - return Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly) + return _fileSystem.GetFileSystemEntryPaths(path) .Select(dir => new VirtualFolderInfo { Name = Path.GetFileName(dir), diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs index c4fe7e43b..42fc73488 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs @@ -54,7 +54,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg info.FFMpegFilename = "ffmpeg.exe"; info.FFProbeFilename = "ffprobe.exe"; - info.Version = "20150916"; + info.Version = "20150918"; info.ArchiveType = "7z"; switch (environment.SystemArchitecture) @@ -83,14 +83,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case Architecture.X86_X64: return new[] { - "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20150916-git-cbbd906-win64-static.7z", - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150916-git-cbbd906-win64-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150918-win64.7z", + "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20150916-git-cbbd906-win64-static.7z" }; case Architecture.X86: return new[] { - "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150916-git-cbbd906-win32-static.7z", - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150916-git-cbbd906-win32-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150918-win32.7z", + "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150916-git-cbbd906-win32-static.7z" }; } break; diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 558f7f5ca..c172cf40c 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.633 + 3.0.634 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption. Copyright © Emby 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 04d4deb7c..978661b6e 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.633 + 3.0.634 MediaBrowser.Common Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 2a75ac3a8..767117167 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.633 + 3.0.634 MediaBrowser.Model - Signed Edition Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index da8309410..29c9509eb 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.633 + 3.0.634 Media Browser.Server.Core Emby Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Emby Server. Copyright © Emby 2013 - + -- cgit v1.2.3 From 8ad702060ea31a3862598056509a2597f6a2b639 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 3 Oct 2015 23:38:46 -0400 Subject: begin file system rework --- MediaBrowser.Api/Playback/Dash/MpegDashService.cs | 4 +- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 4 +- MediaBrowser.Api/System/SystemService.cs | 4 +- .../IO/CommonFileSystem.cs | 134 ++++++++++++------- MediaBrowser.Common/IO/FileSystemMetadata.cs | 32 +++++ MediaBrowser.Common/IO/IFileSystem.cs | 145 ++++++++++++++++++--- MediaBrowser.Common/MediaBrowser.Common.csproj | 1 + .../Entities/AggregateFolder.cs | 7 +- MediaBrowser.Controller/Entities/BaseItem.cs | 37 +++--- .../Entities/CollectionFolder.cs | 7 +- MediaBrowser.Controller/Entities/Folder.cs | 5 +- MediaBrowser.Controller/Entities/IHasImages.cs | 9 +- MediaBrowser.Controller/Entities/Movies/Movie.cs | 5 +- MediaBrowser.Controller/Entities/Video.cs | 3 +- MediaBrowser.Controller/IO/FileData.cs | 6 +- MediaBrowser.Controller/Library/ILibraryManager.cs | 19 ++- MediaBrowser.Controller/Library/ItemResolveArgs.cs | 15 ++- .../Providers/DirectoryService.cs | 28 ++-- .../Providers/IDirectoryService.cs | 13 +- .../Providers/LocalImageInfo.cs | 3 +- MediaBrowser.Controller/Resolvers/IItemResolver.cs | 9 +- MediaBrowser.LocalMetadata/BaseXmlProvider.cs | 2 +- .../Images/EpisodeLocalImageProvider.cs | 4 +- .../Images/LocalImageProvider.cs | 26 ++-- .../Parsers/EpisodeXmlParser.cs | 7 +- .../Providers/BoxSetXmlProvider.cs | 2 +- .../Providers/EpisodeXmlProvider.cs | 4 +- .../Providers/FolderXmlProvider.cs | 4 +- .../Providers/GameSystemXmlProvider.cs | 2 +- .../Providers/GameXmlProvider.cs | 6 +- .../Providers/MovieXmlProvider.cs | 15 +-- .../Providers/MusicVideoXmlProvider.cs | 2 +- .../Providers/PersonXmlProvider.cs | 2 +- .../Providers/PlaylistXmlProvider.cs | 2 +- .../Providers/SeasonXmlProvider.cs | 2 +- .../Providers/SeriesXmlProvider.cs | 2 +- .../Providers/VideoXmlProvider.cs | 2 +- MediaBrowser.Model/Devices/DeviceInfo.cs | 5 +- MediaBrowser.Providers/ImagesByName/ImageUtils.cs | 2 +- MediaBrowser.Providers/Manager/ImageSaver.cs | 2 +- .../MediaInfo/SubtitleResolver.cs | 2 +- .../Movies/FanArtMovieUpdatesPostScanTask.cs | 2 +- .../Movies/FanartMovieImageProvider.cs | 2 +- MediaBrowser.Providers/Movies/MovieDbProvider.cs | 2 +- .../Movies/MovieUpdatesPrescanTask.cs | 2 +- .../Music/FanArtAlbumProvider.cs | 2 +- .../Music/FanArtArtistProvider.cs | 2 +- .../Music/FanArtUpdatesPostScanTask.cs | 2 +- MediaBrowser.Providers/TV/FanArtSeasonProvider.cs | 2 +- .../TV/FanArtTvUpdatesPostScanTask.cs | 2 +- MediaBrowser.Providers/TV/FanartSeriesProvider.cs | 2 +- MediaBrowser.Providers/TV/MovieDbSeriesProvider.cs | 2 +- .../TV/TvdbEpisodeImageProvider.cs | 2 +- MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs | 10 +- MediaBrowser.Providers/TV/TvdbPrescanTask.cs | 2 +- .../TV/TvdbSeasonImageProvider.cs | 2 +- .../TV/TvdbSeriesImageProvider.cs | 2 +- .../Channels/ChannelManager.cs | 11 +- .../Dto/DtoService.cs | 2 +- .../FileOrganization/TvFolderOrganizer.cs | 17 ++- .../IO/LibraryMonitor.cs | 5 +- .../Library/LibraryManager.cs | 66 +++++++--- .../Library/ResolverHelper.cs | 4 +- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 2 +- .../Library/Resolvers/Movies/MovieResolver.cs | 19 +-- .../Library/Resolvers/TV/SeriesResolver.cs | 2 +- .../LiveTv/LiveTvManager.cs | 2 +- .../Sync/SyncJobProcessor.cs | 2 +- .../ApplicationHost.cs | 2 +- .../Providers/AlbumNfoProvider.cs | 2 +- .../Providers/ArtistNfoProvider.cs | 2 +- .../Providers/BaseNfoProvider.cs | 2 +- .../Providers/BaseVideoNfoProvider.cs | 2 +- .../Providers/EpisodeNfoProvider.cs | 2 +- .../Providers/SeasonNfoProvider.cs | 2 +- .../Providers/SeriesNfoProvider.cs | 2 +- MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs | 14 +- 77 files changed, 505 insertions(+), 282 deletions(-) create mode 100644 MediaBrowser.Common/IO/FileSystemMetadata.cs (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs') diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs index cbee821d2..5a36b0aa2 100644 --- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs @@ -322,7 +322,7 @@ namespace MediaBrowser.Api.Playback.Dash } } - private static List GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count) + private static List GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count) { var folder = Path.GetDirectoryName(playlist); @@ -336,7 +336,7 @@ namespace MediaBrowser.Api.Playback.Dash } catch (DirectoryNotFoundException) { - return new List(); + return new List(); } } diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index cb49e65c7..39bdee699 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -354,7 +354,7 @@ namespace MediaBrowser.Api.Playback.Hls } } - private void DeleteFile(FileInfo file, int retryCount) + private void DeleteFile(FileSystemMetadata file, int retryCount) { if (retryCount >= 5) { @@ -378,7 +378,7 @@ namespace MediaBrowser.Api.Playback.Hls } } - private static FileInfo GetLastTranscodingFile(string playlist, string segmentExtension, IFileSystem fileSystem) + private static FileSystemMetadata GetLastTranscodingFile(string playlist, string segmentExtension, IFileSystem fileSystem) { var folder = Path.GetDirectoryName(playlist); diff --git a/MediaBrowser.Api/System/SystemService.cs b/MediaBrowser.Api/System/SystemService.cs index 00935dd1e..4ad8b3903 100644 --- a/MediaBrowser.Api/System/SystemService.cs +++ b/MediaBrowser.Api/System/SystemService.cs @@ -118,7 +118,7 @@ namespace MediaBrowser.Api.System public object Get(GetServerLogs request) { - List files; + List files; try { @@ -128,7 +128,7 @@ namespace MediaBrowser.Api.System } catch (DirectoryNotFoundException) { - files = new List(); + files = new List(); } var result = files.Select(i => new LogFile diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index b899e88c2..f13b9b1a9 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Common.Implementations.IO SetInvalidFileNameChars(usePresetInvalidFileNameChars); } - private void SetInvalidFileNameChars(bool usePresetInvalidFileNameChars) + protected void SetInvalidFileNameChars(bool usePresetInvalidFileNameChars) { // GetInvalidFileNameChars is less restrictive in Linux/Mac than Windows, this mimic Windows behavior for mono under Linux/Mac. @@ -115,7 +115,7 @@ namespace MediaBrowser.Common.Implementations.IO /// /// The path. /// FileSystemInfo. - public FileSystemInfo GetFileSystemInfo(string path) + public FileSystemMetadata GetFileSystemInfo(string path) { if (string.IsNullOrEmpty(path)) { @@ -129,10 +129,10 @@ namespace MediaBrowser.Common.Implementations.IO if (fileInfo.Exists) { - return fileInfo; + return GetFileSystemMetadata(fileInfo); } - return new DirectoryInfo(path); + return GetFileSystemMetadata(new DirectoryInfo(path)); } else { @@ -140,13 +140,63 @@ namespace MediaBrowser.Common.Implementations.IO if (fileInfo.Exists) { - return fileInfo; + return GetFileSystemMetadata(fileInfo); } - return new FileInfo(path); + return GetFileSystemMetadata(new FileInfo(path)); } } + public FileSystemMetadata GetFileInfo(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + + var fileInfo = new FileInfo(path); + + return GetFileSystemMetadata(fileInfo); + } + + public FileSystemMetadata GetDirectoryInfo(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + + var fileInfo = new DirectoryInfo(path); + + return GetFileSystemMetadata(fileInfo); + } + + private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info) + { + var result = new FileSystemMetadata(); + + result.Attributes = info.Attributes; + result.Exists = info.Exists; + result.FullName = info.FullName; + result.Extension = info.Extension; + result.Name = info.Name; + + if (result.Exists) + { + var fileInfo = info as FileInfo; + if (fileInfo != null) + { + result.Length = fileInfo.Length; + result.DirectoryName = fileInfo.DirectoryName; + } + + result.CreationTimeUtc = GetCreationTimeUtc(info); + result.LastWriteTimeUtc = GetLastWriteTimeUtc(info); + } + + return result; + } + /// /// The space char /// @@ -194,6 +244,26 @@ namespace MediaBrowser.Common.Implementations.IO } } + /// + /// Gets the creation time UTC. + /// + /// The path. + /// DateTime. + public DateTime GetCreationTimeUtc(string path) + { + return GetCreationTimeUtc(GetFileSystemInfo(path)); + } + + public DateTime GetCreationTimeUtc(FileSystemMetadata info) + { + return info.CreationTimeUtc; + } + + public DateTime GetLastWriteTimeUtc(FileSystemMetadata info) + { + return info.LastWriteTimeUtc; + } + /// /// Gets the creation time UTC. /// @@ -346,41 +416,9 @@ namespace MediaBrowser.Common.Implementations.IO return path.TrimEnd(Path.DirectorySeparatorChar); } - public string SubstitutePath(string path, string from, string to) + public string GetFileNameWithoutExtension(FileSystemMetadata info) { - if (string.IsNullOrWhiteSpace(path)) - { - throw new ArgumentNullException("path"); - } - if (string.IsNullOrWhiteSpace(from)) - { - throw new ArgumentNullException("from"); - } - if (string.IsNullOrWhiteSpace(to)) - { - throw new ArgumentNullException("to"); - } - - var newPath = path.Replace(from, to, StringComparison.OrdinalIgnoreCase); - - if (!string.Equals(newPath, path)) - { - if (to.IndexOf('/') != -1) - { - newPath = newPath.Replace('\\', '/'); - } - else - { - newPath = newPath.Replace('/', '\\'); - } - } - - return newPath; - } - - public string GetFileNameWithoutExtension(FileSystemInfo info) - { - if (info is DirectoryInfo) + if (info.IsDirectory) { return info.Name; } @@ -426,28 +464,28 @@ namespace MediaBrowser.Common.Implementations.IO { Directory.CreateDirectory(path); } - - public IEnumerable GetDirectories(string path, bool recursive = false) + + public IEnumerable GetDirectories(string path, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return new DirectoryInfo (path).EnumerateDirectories("*", searchOption); + return new DirectoryInfo(path).EnumerateDirectories("*", searchOption).Select(GetFileSystemMetadata); } - public IEnumerable GetFiles(string path, bool recursive = false) + public IEnumerable GetFiles(string path, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return new DirectoryInfo (path).EnumerateFiles("*", searchOption); + return new DirectoryInfo (path).EnumerateFiles("*", searchOption).Select(GetFileSystemMetadata); } - public IEnumerable GetFileSystemEntries(string path, bool recursive = false) + public IEnumerable GetFileSystemEntries(string path, bool recursive = false) { var directoryInfo = new DirectoryInfo (path); var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return directoryInfo.EnumerateDirectories("*", searchOption) - .Concat(directoryInfo.EnumerateFiles("*", searchOption)); + return directoryInfo.EnumerateDirectories("*", searchOption).Select(GetFileSystemMetadata) + .Concat(directoryInfo.EnumerateFiles("*", searchOption).Select(GetFileSystemMetadata)); } public Stream OpenRead(string path) diff --git a/MediaBrowser.Common/IO/FileSystemMetadata.cs b/MediaBrowser.Common/IO/FileSystemMetadata.cs new file mode 100644 index 000000000..ba8a1b8b8 --- /dev/null +++ b/MediaBrowser.Common/IO/FileSystemMetadata.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.IO +{ + public class FileSystemMetadata + { + public FileAttributes Attributes { get; set; } + + public bool Exists { get; set; } + public string FullName { get; set; } + public string Name { get; set; } + public string Extension { get; set; } + public long Length { get; set; } + public string DirectoryName { get; set; } + + public DateTime LastWriteTimeUtc { get; set; } + public DateTime CreationTimeUtc { get; set; } + + public bool IsDirectory + { + get + { + return (Attributes & FileAttributes.Directory) == FileAttributes.Directory; + } + } + } +} diff --git a/MediaBrowser.Common/IO/IFileSystem.cs b/MediaBrowser.Common/IO/IFileSystem.cs index ce15ad999..e084f94ed 100644 --- a/MediaBrowser.Common/IO/IFileSystem.cs +++ b/MediaBrowser.Common/IO/IFileSystem.cs @@ -36,8 +36,22 @@ namespace MediaBrowser.Common.IO /// /// The path. /// FileSystemInfo. - FileSystemInfo GetFileSystemInfo(string path); + FileSystemMetadata GetFileSystemInfo(string path); + /// + /// Gets the file information. + /// + /// The path. + /// FileSystemMetadata. + FileSystemMetadata GetFileInfo(string path); + + /// + /// Gets the directory information. + /// + /// The path. + /// FileSystemMetadata. + FileSystemMetadata GetDirectoryInfo(string path); + /// /// Gets the valid filename. /// @@ -48,17 +62,24 @@ namespace MediaBrowser.Common.IO /// /// Gets the creation time UTC. /// - /// The info. + /// The information. + /// DateTime. + DateTime GetCreationTimeUtc(FileSystemMetadata info); + + /// + /// Gets the creation time UTC. + /// + /// The path. /// DateTime. - DateTime GetCreationTimeUtc(FileSystemInfo info); + DateTime GetCreationTimeUtc(string path); /// /// Gets the last write time UTC. /// /// The information. /// DateTime. - DateTime GetLastWriteTimeUtc(FileSystemInfo info); - + DateTime GetLastWriteTimeUtc(FileSystemMetadata info); + /// /// Gets the last write time UTC. /// @@ -77,6 +98,11 @@ namespace MediaBrowser.Common.IO /// FileStream. Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false); + /// + /// Opens the read. + /// + /// The path. + /// Stream. Stream OpenRead(String path); /// @@ -108,21 +134,12 @@ namespace MediaBrowser.Common.IO /// System.String. string NormalizePath(string path); - /// - /// Substitutes the path. - /// - /// The path. - /// From. - /// To. - /// System.String. - string SubstitutePath(string path, string from, string to); - /// /// Gets the file name without extension. /// /// The information. /// System.String. - string GetFileNameWithoutExtension(FileSystemInfo info); + string GetFileNameWithoutExtension(FileSystemMetadata info); /// /// Gets the file name without extension. @@ -150,37 +167,125 @@ namespace MediaBrowser.Common.IO /// The path. /// if set to true [recursive]. void DeleteDirectory(string path, bool recursive); - - IEnumerable GetDirectories(string path, bool recursive = false); - IEnumerable GetFiles(string path, bool recursive = false); + /// + /// Gets the directories. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<DirectoryInfo>. + IEnumerable GetDirectories(string path, bool recursive = false); - IEnumerable GetFileSystemEntries(string path, bool recursive = false); + /// + /// Gets the files. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<FileInfo>. + IEnumerable GetFiles(string path, bool recursive = false); + + /// + /// Gets the file system entries. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<FileSystemMetadata>. + IEnumerable GetFileSystemEntries(string path, bool recursive = false); + /// + /// Creates the directory. + /// + /// The path. void CreateDirectory(string path); + /// + /// Copies the file. + /// + /// The source. + /// The target. + /// if set to true [overwrite]. void CopyFile(string source, string target, bool overwrite); + /// + /// Moves the file. + /// + /// The source. + /// The target. void MoveFile(string source, string target); + /// + /// Moves the directory. + /// + /// The source. + /// The target. void MoveDirectory(string source, string target); + /// + /// Directories the exists. + /// + /// The path. + /// true if XXXX, false otherwise. bool DirectoryExists(string path); + /// + /// Files the exists. + /// + /// The path. + /// true if XXXX, false otherwise. bool FileExists(string path); + /// + /// Reads all text. + /// + /// The path. + /// System.String. string ReadAllText(string path); + /// + /// Writes all text. + /// + /// The path. + /// The text. void WriteAllText(string path, string text); - + + /// + /// Writes all text. + /// + /// The path. + /// The text. + /// The encoding. void WriteAllText(string path, string text, Encoding encoding); + /// + /// Reads all text. + /// + /// The path. + /// The encoding. + /// System.String. string ReadAllText(string path, Encoding encoding); + /// + /// Gets the directory paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetDirectoryPaths(string path, bool recursive = false); + /// + /// Gets the file paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetFilePaths(string path, bool recursive = false); + /// + /// Gets the file system entry paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetFileSystemEntryPaths(string path, bool recursive = false); } } diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index ad0c0cecd..0476f3f60 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -60,6 +60,7 @@ + diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index 66a0d551b..5af02e9bb 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Providers; namespace MediaBrowser.Controller.Entities @@ -62,7 +63,7 @@ namespace MediaBrowser.Controller.Entities public List PhysicalLocationsList { get; set; } - protected override IEnumerable GetFileSystemChildren(IDirectoryService directoryService) + protected override IEnumerable GetFileSystemChildren(IDirectoryService directoryService) { return CreateResolveArgs(directoryService).FileSystemChildren; } @@ -73,7 +74,7 @@ namespace MediaBrowser.Controller.Entities var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths , directoryService) { - FileInfo = new DirectoryInfo(path), + FileInfo = FileSystem.GetDirectoryInfo(path), Path = path, Parent = Parent }; @@ -94,7 +95,7 @@ namespace MediaBrowser.Controller.Entities { var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); - fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName); + fileSystemDictionary = paths.Select(FileSystem.GetDirectoryInfo).ToDictionary(i => i.FullName); } args.FileSystemDictionary = fileSystemDictionary; diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 5403c16dd..963f4725a 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -676,7 +676,7 @@ namespace MediaBrowser.Controller.Entities /// Loads the theme songs. /// /// List{Audio.Audio}. - private IEnumerable LoadThemeSongs(List fileSystemChildren, IDirectoryService directoryService) + private IEnumerable LoadThemeSongs(List fileSystemChildren, IDirectoryService directoryService) { var files = fileSystemChildren.OfType() .Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) @@ -684,8 +684,8 @@ namespace MediaBrowser.Controller.Entities .ToList(); // Support plex/xbmc convention - files.AddRange(fileSystemChildren.OfType() - .Where(i => string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) + files.AddRange(fileSystemChildren + .Where(i => !i.IsDirectory && string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) ); return LibraryManager.ResolvePaths(files, directoryService, null) @@ -712,7 +712,7 @@ namespace MediaBrowser.Controller.Entities /// Loads the video backdrops. /// /// List{Video}. - private IEnumerable /// true if XXXX, false otherwise - private bool RefreshLinkedChildren(IEnumerable fileSystemChildren) + private bool RefreshLinkedChildren(IEnumerable fileSystemChildren) { var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList(); var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList(); diff --git a/MediaBrowser.Controller/Entities/IHasImages.cs b/MediaBrowser.Controller/Entities/IHasImages.cs index ffb351c94..55c5f7e11 100644 --- a/MediaBrowser.Controller/Entities/IHasImages.cs +++ b/MediaBrowser.Controller/Entities/IHasImages.cs @@ -3,6 +3,7 @@ using MediaBrowser.Model.Entities; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Controller.Entities { @@ -67,7 +68,7 @@ namespace MediaBrowser.Controller.Entities /// The type. /// The index. /// The file. - void SetImagePath(ImageType type, int index, FileSystemInfo file); + void SetImagePath(ImageType type, int index, FileSystemMetadata file); /// /// Determines whether the specified type has image. @@ -134,7 +135,7 @@ namespace MediaBrowser.Controller.Entities /// Type of the image. /// The images. /// true if XXXX, false otherwise. - bool AddImages(ImageType imageType, List images); + bool AddImages(ImageType imageType, List images); /// /// Determines whether [is save local metadata enabled]. @@ -215,7 +216,7 @@ namespace MediaBrowser.Controller.Entities /// The item. /// Type of the image. /// The file. - public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemInfo file) + public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemMetadata file) { item.SetImagePath(imageType, 0, file); } @@ -228,7 +229,7 @@ namespace MediaBrowser.Controller.Entities /// The file. public static void SetImagePath(this IHasImages item, ImageType imageType, string file) { - item.SetImagePath(imageType, new FileInfo(file)); + item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file)); } } } diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index 083ec0cb4..8910fdbdd 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Controller.Entities.Movies { @@ -122,7 +123,7 @@ namespace MediaBrowser.Controller.Entities.Movies return key; } - protected override async Task RefreshedOwnedItems(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) + protected override async Task RefreshedOwnedItems(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) { var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false); @@ -141,7 +142,7 @@ namespace MediaBrowser.Controller.Entities.Movies return hasChanges; } - private async Task RefreshSpecialFeatures(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) + private async Task RefreshSpecialFeatures(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) { var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList(); var newItemIds = newItems.Select(i => i.Id).ToList(); diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 21405faf1..5f5743b1d 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Controller.Entities { @@ -343,7 +344,7 @@ namespace MediaBrowser.Controller.Entities } } - protected override async Task RefreshedOwnedItems(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) + protected override async Task RefreshedOwnedItems(MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) { var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index fb0f07331..503727e14 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.IO /// if set to true [resolve shortcuts]. /// Dictionary{System.StringFileSystemInfo}. /// path - public static Dictionary GetFilteredFileSystemEntries(IDirectoryService directoryService, + public static Dictionary GetFilteredFileSystemEntries(IDirectoryService directoryService, string path, IFileSystem fileSystem, ILogger logger, @@ -49,7 +49,7 @@ namespace MediaBrowser.Controller.IO var entries = directoryService.GetFileSystemEntries(path); - var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var entry in entries) { @@ -69,7 +69,7 @@ namespace MediaBrowser.Controller.IO } // Don't check if it exists here because that could return false for network shares. - var data = new DirectoryInfo(newPath); + var data = fileSystem.GetDirectoryInfo(newPath); // add to our physical locations args.AddAdditionalLocation(newPath); diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 9331ca759..93f291aae 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Controller.Library { @@ -25,19 +26,18 @@ namespace MediaBrowser.Controller.Library /// The file information. /// The parent. /// BaseItem. - BaseItem ResolvePath(FileSystemInfo fileInfo, + BaseItem ResolvePath(FileSystemMetadata fileInfo, Folder parent = null); /// /// Resolves a set of files into a list of BaseItem /// - /// /// The files. /// The directory service. /// The parent. /// Type of the collection. /// List{``0}. - IEnumerable ResolvePaths(IEnumerable files, + IEnumerable ResolvePaths(IEnumerable files, IDirectoryService directoryService, Folder parent, string collectionType = null); @@ -434,7 +434,7 @@ namespace MediaBrowser.Controller.Library /// The file system children. /// The directory service. /// IEnumerable<Trailer>. - IEnumerable