diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-02-08 17:38:02 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-02-08 17:38:02 -0500 |
| commit | 7f5a4c2d4e3d8e1881dae0403367e35ad5699eaf (patch) | |
| tree | b8cd714ee0c027c49001f263be885511954f5787 /MediaBrowser.Controller/Providers/DirectoryService.cs | |
| parent | 3ffd95a6371c40246a8163c17da3626374685271 (diff) | |
added item type to refresh info
Diffstat (limited to 'MediaBrowser.Controller/Providers/DirectoryService.cs')
| -rw-r--r-- | MediaBrowser.Controller/Providers/DirectoryService.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs new file mode 100644 index 000000000..961f3acc7 --- /dev/null +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MediaBrowser.Model.Logging; + +namespace MediaBrowser.Controller.Providers +{ + public class DirectoryService + { + private readonly ILogger _logger; + + private readonly Dictionary<string, List<FileSystemInfo>> _cache = new Dictionary<string, List<FileSystemInfo>>(StringComparer.OrdinalIgnoreCase); + + public DirectoryService(ILogger logger) + { + _logger = logger; + } + + public List<FileSystemInfo> GetFileSystemEntries(string path) + { + List<FileSystemInfo> entries; + + if (!_cache.TryGetValue(path, out entries)) + { + //_logger.Debug("Getting files for " + path); + + entries = new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList(); + _cache.Add(path, entries); + } + + return entries; + } + + public IEnumerable<FileInfo> GetFiles(string path) + { + return GetFileSystemEntries(path).OfType<FileInfo>(); + } + + public IEnumerable<DirectoryInfo> GetDirectories(string path) + { + return GetFileSystemEntries(path).OfType<DirectoryInfo>(); + } + + public FileInfo GetFile(string path) + { + var directory = Path.GetDirectoryName(path); + var filename = Path.GetFileName(path); + + return GetFiles(directory).FirstOrDefault(i => string.Equals(i.Name, filename, StringComparison.OrdinalIgnoreCase)); + } + + + public DirectoryInfo GetDirectory(string path) + { + var directory = Path.GetDirectoryName(path); + var name = Path.GetFileName(path); + + return GetDirectories(directory).FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + } + } +} |
