jellyfin/Emby.Naming/Video/FileStack.cs

57 lines
1.8 KiB
C#
Raw Normal View History

using System;
2018-09-12 17:26:21 +00:00
using System.Collections.Generic;
2021-12-20 12:31:07 +00:00
using Jellyfin.Extensions;
2018-09-12 17:26:21 +00:00
namespace Emby.Naming.Video
{
2020-11-10 18:23:10 +00:00
/// <summary>
/// Object holding list of files paths with additional information.
/// </summary>
2018-09-12 17:26:21 +00:00
public class FileStack
{
2020-11-10 18:23:10 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="FileStack"/> class.
/// </summary>
2021-12-10 13:23:31 +00:00
/// <param name="name">The stack name.</param>
/// <param name="isDirectory">Whether the stack files are directories.</param>
/// <param name="files">The stack files.</param>
public FileStack(string name, bool isDirectory, IReadOnlyList<string> files)
2018-09-12 17:26:21 +00:00
{
2021-12-10 13:23:31 +00:00
Name = name;
IsDirectoryStack = isDirectory;
Files = files;
2018-09-12 17:26:21 +00:00
}
2020-11-10 18:23:10 +00:00
/// <summary>
2021-12-10 13:23:31 +00:00
/// Gets the name of file stack.
2020-11-10 18:23:10 +00:00
/// </summary>
2021-12-10 13:23:31 +00:00
public string Name { get; }
2020-11-10 18:23:10 +00:00
/// <summary>
2021-12-10 13:23:31 +00:00
/// Gets the list of paths in stack.
2020-11-10 18:23:10 +00:00
/// </summary>
2021-12-10 13:23:31 +00:00
public IReadOnlyList<string> Files { get; }
2020-11-10 18:23:10 +00:00
/// <summary>
2021-12-10 13:23:31 +00:00
/// Gets a value indicating whether stack is directory stack.
2020-11-10 18:23:10 +00:00
/// </summary>
2021-12-10 13:23:31 +00:00
public bool IsDirectoryStack { get; }
2020-11-10 18:23:10 +00:00
/// <summary>
/// Helper function to determine if path is in the stack.
/// </summary>
/// <param name="file">Path of desired file.</param>
/// <param name="isDirectory">Requested type of stack.</param>
/// <returns>True if file is in the stack.</returns>
2019-05-10 18:37:42 +00:00
public bool ContainsFile(string file, bool isDirectory)
2018-09-12 17:26:21 +00:00
{
2021-12-07 14:18:17 +00:00
if (string.IsNullOrEmpty(file))
{
return false;
}
2021-12-20 12:31:07 +00:00
return IsDirectoryStack == isDirectory && Files.Contains(file, StringComparison.OrdinalIgnoreCase);
2018-09-12 17:26:21 +00:00
}
}
}