// Media Folder // // Douglas Thrift // // $Id$ using System; using System.Collections.Generic; using System.IO; public class MediaFolder { public SortedDictionary files { get { return files_; } } public SortedDictionary folders { get { return folders_; } } public MediaFolder(DirectoryInfo folder, List extensions) { foreach (string extension in extensions) foreach (FileInfo file in folder.GetFiles("*." + extension)) files_[file.Name] = new MediaFile(file); foreach (DirectoryInfo folder_ in folder.GetDirectories()) folders_[folder_.Name] = new MediaFolder(folder_, extensions); } public long Get(string path, out Stream stream) { char[] slash = { '/' }; string[] path_ = path.Split(slash, 2, StringSplitOptions.RemoveEmptyEntries); MediaFolder folder; if (path_.Length == 2 && folders_.TryGetValue(path_[0], out folder)) return folder.Get(path_[1], out stream); MediaFile file; if (path_.Length == 1 && files_.TryGetValue(path_[0], out file)) return file.Get(out stream); stream = null; return 0; } private SortedDictionary files_ = new SortedDictionary(); private SortedDictionary folders_ = new SortedDictionary(); }