FileStack.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using Jellyfin.Extensions;
  4. namespace Emby.Naming.Video
  5. {
  6. /// <summary>
  7. /// Object holding list of files paths with additional information.
  8. /// </summary>
  9. public class FileStack
  10. {
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="FileStack"/> class.
  13. /// </summary>
  14. /// <param name="name">The stack name.</param>
  15. /// <param name="isDirectory">Whether the stack files are directories.</param>
  16. /// <param name="files">The stack files.</param>
  17. public FileStack(string name, bool isDirectory, IReadOnlyList<string> files)
  18. {
  19. Name = name;
  20. IsDirectoryStack = isDirectory;
  21. Files = files;
  22. }
  23. /// <summary>
  24. /// Gets the name of file stack.
  25. /// </summary>
  26. public string Name { get; }
  27. /// <summary>
  28. /// Gets the list of paths in stack.
  29. /// </summary>
  30. public IReadOnlyList<string> Files { get; }
  31. /// <summary>
  32. /// Gets a value indicating whether stack is directory stack.
  33. /// </summary>
  34. public bool IsDirectoryStack { get; }
  35. /// <summary>
  36. /// Helper function to determine if path is in the stack.
  37. /// </summary>
  38. /// <param name="file">Path of desired file.</param>
  39. /// <param name="isDirectory">Requested type of stack.</param>
  40. /// <returns>True if file is in the stack.</returns>
  41. public bool ContainsFile(string file, bool isDirectory)
  42. {
  43. if (string.IsNullOrEmpty(file))
  44. {
  45. return false;
  46. }
  47. return IsDirectoryStack == isDirectory && Files.Contains(file, StringComparison.OrdinalIgnoreCase);
  48. }
  49. }
  50. }