123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using MediaBrowser.Controller.IO;
- using MediaBrowser.Model.Entities;
- namespace MediaBrowser.Controller.Events
- {
- /// <summary>
- /// This is an EventArgs object used when resolving a Path into a BaseItem
- /// </summary>
- public class ItemResolveEventArgs : PreBeginResolveEventArgs
- {
- public KeyValuePair<string, WIN32_FIND_DATA>[] FileSystemChildren { get; set; }
- public KeyValuePair<string, WIN32_FIND_DATA>? GetFileSystemEntry(string path, bool? isFolder)
- {
- for (int i = 0; i < FileSystemChildren.Length; i++)
- {
- KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
- 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)
- {
- for (int i = 0; i < FileSystemChildren.Length; i++)
- {
- KeyValuePair<string, WIN32_FIND_DATA> entry = FileSystemChildren[i];
- 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;
- }
- }
- }
- }
|