2012-07-26 02:33:11 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Controller.Xml;
|
2012-07-26 02:33:11 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
|
|
|
|
{
|
2012-07-26 02:33:11 +00:00
|
|
|
|
[Export(typeof(IBaseItemResolver))]
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public class FolderResolver : BaseFolderResolver<Folder>
|
|
|
|
|
{
|
|
|
|
|
protected override Folder Resolve(ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
return new Folder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class BaseFolderResolver<T> : BaseItemResolver<T>
|
|
|
|
|
where T : Folder, new ()
|
|
|
|
|
{
|
|
|
|
|
protected override void SetItemValues(T item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
base.SetItemValues(item, args);
|
|
|
|
|
|
|
|
|
|
item.IsRoot = args.Parent == null;
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// Read data from folder.xml, if it exists
|
2012-07-12 06:55:27 +00:00
|
|
|
|
PopulateFolderMetadata(item, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateFolderMetadata(Folder folder, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var metadataFile = args.GetFileByName("folder.xml");
|
|
|
|
|
|
|
|
|
|
if (metadataFile.HasValue)
|
|
|
|
|
{
|
|
|
|
|
new FolderXmlParser().Fetch(folder, metadataFile.Value.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|