aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Library/ItemResolveEventArgs.cs
blob: 32b8783dfdf7378e567f6954b10f58a1c8892f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using System.Collections.Generic;
using System.Linq;
using System;
using System.IO;

namespace MediaBrowser.Controller.Library
{
    /// <summary>
    /// This is an EventArgs object used when resolving a Path into a BaseItem
    /// </summary>
    public class ItemResolveEventArgs : PreBeginResolveEventArgs
    {
        public WIN32_FIND_DATA[] FileSystemChildren { get; set; }

        protected List<string> _additionalLocations = new List<string>();
        public List<string> AdditionalLocations
        {
            get
            {
                return _additionalLocations;
            }
            set
            {
                _additionalLocations = value;
            }
        }

        public IEnumerable<string> PhysicalLocations
        {
            get
            {
                return (new List<string>() {this.Path}).Concat(AdditionalLocations);
            }
        }

        public bool IsBDFolder { get; set; }
        public bool IsDVDFolder { get; set; }
        public bool IsHDDVDFolder { get; set; }

        /// <summary>
        /// Store these to reduce disk access in Resolvers
        /// </summary>
        public string[] MetadataFiles { get; set; }

        public WIN32_FIND_DATA? GetFileSystemEntry(string path)
        {
            WIN32_FIND_DATA entry = FileSystemChildren.FirstOrDefault(f => f.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
            return entry.cFileName != null ? (WIN32_FIND_DATA?)entry : null;
        }

        public bool ContainsFile(string name)
        {
            return FileSystemChildren.FirstOrDefault(f => f.cFileName.Equals(name, StringComparison.OrdinalIgnoreCase)).cFileName != null;
        }

        public bool ContainsFolder(string name)
        {
            return ContainsFile(name);
        }
    }

    /// <summary>
    /// This is an EventArgs object used before we begin resolving a Path into a BaseItem
    /// File system children have not been collected yet, but consuming events will
    /// have a chance to cancel resolution based on the Path, Parent and FileAttributes
    /// </summary>
    public class PreBeginResolveEventArgs : EventArgs
    {
        public Folder Parent { get; set; }

        public bool Cancel { get; set; }

        public WIN32_FIND_DATA FileInfo { get; set; }

        public string Path { get; set; }

        public bool IsDirectory
        {
            get
            {
                return FileInfo.dwFileAttributes.HasFlag(FileAttributes.Directory);
            }
        }

        public bool IsHidden
        {
            get
            {
                return FileInfo.IsHidden;
            }
        }

        public bool IsSystemFile
        {
            get
            {
                return FileInfo.IsSystemFile;
            }
        }

    }
}