jellyfin-server/MediaBrowser.Controller/Resolvers/FolderResolver.cs

46 lines
1.3 KiB
C#
Raw Normal View History

using System.ComponentModel.Composition;
2012-07-12 06:55:27 +00:00
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Xml;
using MediaBrowser.Model.Entities;
2012-07-12 06:55:27 +00:00
namespace MediaBrowser.Controller.Resolvers
{
[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<TItemType> : BaseItemResolver<TItemType>
where TItemType : Folder, new()
2012-07-12 06:55:27 +00:00
{
protected override void SetItemValues(TItemType item, ItemResolveEventArgs args)
2012-07-12 06:55:27 +00:00
{
base.SetItemValues(item, args);
item.IsRoot = args.Parent == null;
// Read data from folder.xml, if it exists
2012-07-12 06:55:27 +00:00
PopulateFolderMetadata(item, args);
}
private void PopulateFolderMetadata(TItemType folder, ItemResolveEventArgs args)
2012-07-12 06:55:27 +00:00
{
var metadataFile = args.GetFileByName("folder.xml");
if (metadataFile.HasValue)
{
new FolderXmlParser().Fetch(folder, metadataFile.Value.Key);
}
}
}
}