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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
using System;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.IO;
namespace MediaBrowser.Controller.Events
{
/// <summary>
/// This is an EventArgs object used when resolving a Path into a BaseItem
/// </summary>
public class ItemResolveEventArgs : PreBeginResolveEventArgs
{
public IEnumerable<KeyValuePair<string, WIN32_FIND_DATA>> FileSystemChildren { get; set; }
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntry(string path, bool? isFolder)
{
foreach (KeyValuePair<string, WIN32_FIND_DATA> entry in FileSystemChildren)
{
if (isFolder.HasValue)
{
if (isFolder.Value && entry.Value.IsDirectory)
{
continue;
}
else if (!isFolder.Value && !entry.Value.IsDirectory)
{
continue;
}
}
if (entry.Key.Equals(path, StringComparison.OrdinalIgnoreCase))
{
return entry;
}
}
return null;
}
public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntryByName(string name, bool? isFolder)
{
foreach (KeyValuePair<string, WIN32_FIND_DATA> entry in FileSystemChildren)
{
if (isFolder.HasValue)
{
if (isFolder.Value && entry.Value.IsDirectory)
{
continue;
}
else if (!isFolder.Value && !entry.Value.IsDirectory)
{
continue;
}
}
if (System.IO.Path.GetFileName(entry.Key).Equals(name, StringComparison.OrdinalIgnoreCase))
{
return entry;
}
}
return null;
}
public bool ContainsFile(string name)
{
return GetFileSystemEntryByName(name, false) != null;
}
public bool ContainsFolder(string name)
{
return GetFileSystemEntryByName(name, true) != null;
}
}
/// <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 string Path { get; set; }
public Folder Parent { get; set; }
public bool Cancel { get; set; }
public FileAttributes FileAttributes { get { return FileData.dwFileAttributes; } }
public WIN32_FIND_DATA FileData { get; set; }
public bool IsFolder
{
get
{
return FileAttributes.HasFlag(FileAttributes.Directory);
}
}
public bool IsHidden
{
get
{
return FileAttributes.HasFlag(FileAttributes.Hidden);
}
}
public bool IsSystemFile
{
get
{
return FileAttributes.HasFlag(FileAttributes.System);
}
}
public VirtualFolder VirtualFolder
{
get
{
if (Parent != null)
{
return Parent.VirtualFolder;
}
return null;
}
}
public string VirtualFolderCollectionType
{
get
{
VirtualFolder vf = VirtualFolder;
if (vf == null)
{
return null;
}
return vf.CollectionType;
}
}
}
}
|