jellyfin/Emby.Naming/Video/FileStack.cs

57 lines
1.8 KiB
C#
Raw Normal View History

using System;
2018-09-12 19:26:21 +02:00
using System.Collections.Generic;
2021-12-20 13:31:07 +01:00
using Jellyfin.Extensions;
2018-09-12 19:26:21 +02:00
namespace Emby.Naming.Video
{
2020-11-10 19:23:10 +01:00
/// <summary>
/// Object holding list of files paths with additional information.
/// </summary>
2018-09-12 19:26:21 +02:00
public class FileStack
{
2020-11-10 19:23:10 +01:00
/// <summary>
/// Initializes a new instance of the <see cref="FileStack"/> class.
/// </summary>
2021-12-10 14:23:31 +01: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 19:26:21 +02:00
{
2021-12-10 14:23:31 +01:00
Name = name;
IsDirectoryStack = isDirectory;
Files = files;
2018-09-12 19:26:21 +02:00
}
2020-11-10 19:23:10 +01:00
/// <summary>
2021-12-10 14:23:31 +01:00
/// Gets the name of file stack.
2020-11-10 19:23:10 +01:00
/// </summary>
2021-12-10 14:23:31 +01:00
public string Name { get; }
2020-11-10 19:23:10 +01:00
/// <summary>
2021-12-10 14:23:31 +01:00
/// Gets the list of paths in stack.
2020-11-10 19:23:10 +01:00
/// </summary>
2021-12-10 14:23:31 +01:00
public IReadOnlyList<string> Files { get; }
2020-11-10 19:23:10 +01:00
/// <summary>
2021-12-10 14:23:31 +01:00
/// Gets a value indicating whether stack is directory stack.
2020-11-10 19:23:10 +01:00
/// </summary>
2021-12-10 14:23:31 +01:00
public bool IsDirectoryStack { get; }
2020-11-10 19:23:10 +01: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 20:37:42 +02:00
public bool ContainsFile(string file, bool isDirectory)
2018-09-12 19:26:21 +02:00
{
2021-12-07 15:18:17 +01:00
if (string.IsNullOrEmpty(file))
{
return false;
}
2021-12-20 13:31:07 +01:00
return IsDirectoryStack == isDirectory && Files.Contains(file, StringComparison.OrdinalIgnoreCase);
2018-09-12 19:26:21 +02:00
}
}
}