2023-02-18 13:42:35 +00:00
|
|
|
using System.IO;
|
2023-02-03 17:49:23 +00:00
|
|
|
using System.Linq;
|
|
|
|
using BDInfo.IO;
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
namespace MediaBrowser.MediaEncoding.BdInfo;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class BdInfoDirectoryInfo.
|
|
|
|
/// </summary>
|
|
|
|
public class BdInfoDirectoryInfo : IDirectoryInfo
|
2023-02-03 17:49:23 +00:00
|
|
|
{
|
2023-02-18 13:42:35 +00:00
|
|
|
private readonly IFileSystem _fileSystem;
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
private readonly FileSystemMetadata _impl;
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BdInfoDirectoryInfo" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fileSystem">The filesystem.</param>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
public BdInfoDirectoryInfo(IFileSystem fileSystem, string path)
|
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
_impl = _fileSystem.GetDirectoryInfo(path);
|
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
|
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
_impl = impl;
|
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the name.
|
|
|
|
/// </summary>
|
|
|
|
public string Name => _impl.Name;
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the full name.
|
|
|
|
/// </summary>
|
|
|
|
public string FullName => _impl.FullName;
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the parent directory information.
|
|
|
|
/// </summary>
|
|
|
|
public IDirectoryInfo? Parent
|
|
|
|
{
|
|
|
|
get
|
2023-02-03 17:49:23 +00:00
|
|
|
{
|
2023-02-18 13:42:35 +00:00
|
|
|
var parentFolder = Path.GetDirectoryName(_impl.FullName);
|
|
|
|
if (parentFolder is not null)
|
2023-02-03 17:49:23 +00:00
|
|
|
{
|
2023-02-18 13:42:35 +00:00
|
|
|
return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
|
2023-02-03 17:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
return null;
|
2023-02-03 17:49:23 +00:00
|
|
|
}
|
2023-02-18 13:42:35 +00:00
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the directories.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>An array with all directories.</returns>
|
|
|
|
public IDirectoryInfo[] GetDirectories()
|
|
|
|
{
|
|
|
|
return _fileSystem.GetDirectories(_impl.FullName)
|
|
|
|
.Select(x => new BdInfoDirectoryInfo(_fileSystem, x))
|
|
|
|
.ToArray();
|
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the files.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>All files of the directory.</returns>
|
|
|
|
public IFileInfo[] GetFiles()
|
|
|
|
{
|
|
|
|
return _fileSystem.GetFiles(_impl.FullName)
|
|
|
|
.Select(x => new BdInfoFileInfo(x))
|
|
|
|
.ToArray();
|
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the files matching a pattern.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="searchPattern">The search pattern.</param>
|
|
|
|
/// <returns>All files of the directory matchign the search pattern.</returns>
|
|
|
|
public IFileInfo[] GetFiles(string searchPattern)
|
|
|
|
{
|
|
|
|
return _fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false)
|
|
|
|
.Select(x => new BdInfoFileInfo(x))
|
|
|
|
.ToArray();
|
|
|
|
}
|
2023-02-03 17:49:23 +00:00
|
|
|
|
2023-02-18 13:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the files matching a pattern and search options.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="searchPattern">The search pattern.</param>
|
|
|
|
/// <param name="searchOption">The search optin.</param>
|
|
|
|
/// <returns>All files of the directory matchign the search pattern and options.</returns>
|
|
|
|
public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption)
|
|
|
|
{
|
|
|
|
return _fileSystem.GetFiles(
|
|
|
|
_impl.FullName,
|
|
|
|
new[] { searchPattern },
|
|
|
|
false,
|
2023-04-06 17:08:53 +00:00
|
|
|
searchOption == SearchOption.AllDirectories)
|
2023-02-18 13:42:35 +00:00
|
|
|
.Select(x => new BdInfoFileInfo(x))
|
|
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the bdinfo of a file system path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fs">The file system.</param>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
/// <returns>The BD directory information of the path on the file system.</returns>
|
|
|
|
public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path)
|
|
|
|
{
|
|
|
|
return new BdInfoDirectoryInfo(fs, path);
|
2023-02-03 17:49:23 +00:00
|
|
|
}
|
|
|
|
}
|