| | | 1 | | using System.IO; |
| | | 2 | | using System.Linq; |
| | | 3 | | using BDInfo.IO; |
| | | 4 | | using MediaBrowser.Model.IO; |
| | | 5 | | |
| | | 6 | | namespace MediaBrowser.MediaEncoding.BdInfo; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Class BdInfoDirectoryInfo. |
| | | 10 | | /// </summary> |
| | | 11 | | public class BdInfoDirectoryInfo : IDirectoryInfo |
| | | 12 | | { |
| | | 13 | | private readonly IFileSystem _fileSystem; |
| | | 14 | | |
| | | 15 | | private readonly FileSystemMetadata _impl; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="BdInfoDirectoryInfo" /> class. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="fileSystem">The filesystem.</param> |
| | | 21 | | /// <param name="path">The path.</param> |
| | | 22 | | public BdInfoDirectoryInfo(IFileSystem fileSystem, string path) |
| | | 23 | | { |
| | 0 | 24 | | _fileSystem = fileSystem; |
| | 0 | 25 | | _impl = _fileSystem.GetDirectoryInfo(path); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl) |
| | | 29 | | { |
| | 0 | 30 | | _fileSystem = fileSystem; |
| | 0 | 31 | | _impl = impl; |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the name. |
| | | 36 | | /// </summary> |
| | 0 | 37 | | public string Name => _impl.Name; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the full name. |
| | | 41 | | /// </summary> |
| | 0 | 42 | | public string FullName => _impl.FullName; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets the parent directory information. |
| | | 46 | | /// </summary> |
| | | 47 | | public IDirectoryInfo? Parent |
| | | 48 | | { |
| | | 49 | | get |
| | | 50 | | { |
| | 0 | 51 | | var parentFolder = Path.GetDirectoryName(_impl.FullName); |
| | 0 | 52 | | if (parentFolder is not null) |
| | | 53 | | { |
| | 0 | 54 | | return new BdInfoDirectoryInfo(_fileSystem, parentFolder); |
| | | 55 | | } |
| | | 56 | | |
| | 0 | 57 | | return null; |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Gets the directories. |
| | | 63 | | /// </summary> |
| | | 64 | | /// <returns>An array with all directories.</returns> |
| | | 65 | | public IDirectoryInfo[] GetDirectories() |
| | | 66 | | { |
| | 0 | 67 | | return _fileSystem.GetDirectories(_impl.FullName) |
| | 0 | 68 | | .Select(x => new BdInfoDirectoryInfo(_fileSystem, x)) |
| | 0 | 69 | | .ToArray(); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Gets the files. |
| | | 74 | | /// </summary> |
| | | 75 | | /// <returns>All files of the directory.</returns> |
| | | 76 | | public IFileInfo[] GetFiles() |
| | | 77 | | { |
| | 0 | 78 | | return _fileSystem.GetFiles(_impl.FullName) |
| | 0 | 79 | | .Select(x => new BdInfoFileInfo(x)) |
| | 0 | 80 | | .ToArray(); |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Gets the files matching a pattern. |
| | | 85 | | /// </summary> |
| | | 86 | | /// <param name="searchPattern">The search pattern.</param> |
| | | 87 | | /// <returns>All files of the directory matching the search pattern.</returns> |
| | | 88 | | public IFileInfo[] GetFiles(string searchPattern) |
| | | 89 | | { |
| | 0 | 90 | | return _fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false) |
| | 0 | 91 | | .Select(x => new BdInfoFileInfo(x)) |
| | 0 | 92 | | .ToArray(); |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Gets the files matching a pattern and search options. |
| | | 97 | | /// </summary> |
| | | 98 | | /// <param name="searchPattern">The search pattern.</param> |
| | | 99 | | /// <param name="searchOption">The search option.</param> |
| | | 100 | | /// <returns>All files of the directory matching the search pattern and options.</returns> |
| | | 101 | | public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption) |
| | | 102 | | { |
| | 0 | 103 | | return _fileSystem.GetFiles( |
| | 0 | 104 | | _impl.FullName, |
| | 0 | 105 | | new[] { searchPattern }, |
| | 0 | 106 | | false, |
| | 0 | 107 | | searchOption == SearchOption.AllDirectories) |
| | 0 | 108 | | .Select(x => new BdInfoFileInfo(x)) |
| | 0 | 109 | | .ToArray(); |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Gets the bdinfo of a file system path. |
| | | 114 | | /// </summary> |
| | | 115 | | /// <param name="fs">The file system.</param> |
| | | 116 | | /// <param name="path">The path.</param> |
| | | 117 | | /// <returns>The BD directory information of the path on the file system.</returns> |
| | | 118 | | public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path) |
| | | 119 | | { |
| | 0 | 120 | | return new BdInfoDirectoryInfo(fs, path); |
| | | 121 | | } |
| | | 122 | | } |