2012-08-18 21:38:27 +02:00
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
|
|
|
|
{
|
|
|
|
|
[Export(typeof(IBaseItemResolver))]
|
|
|
|
|
public class VirtualFolderResolver : BaseFolderResolver<VirtualFolder>
|
|
|
|
|
{
|
2012-08-20 17:55:05 +02:00
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return ResolverPriority.Third; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-18 21:38:27 +02:00
|
|
|
|
protected override VirtualFolder Resolve(ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-08-21 16:42:40 +02:00
|
|
|
|
if (args.IsDirectory && args.Parent != null && args.Parent.IsRoot)
|
2012-08-18 21:38:27 +02:00
|
|
|
|
{
|
|
|
|
|
return new VirtualFolder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 22:38:31 +02:00
|
|
|
|
protected override void SetInitialItemValues(VirtualFolder item, ItemResolveEventArgs args)
|
2012-08-18 21:38:27 +02:00
|
|
|
|
{
|
|
|
|
|
// Set the name initially by stripping off the [CollectionType=...]
|
|
|
|
|
// The name can always be overridden later by folder.xml
|
|
|
|
|
string pathName = Path.GetFileNameWithoutExtension(args.Path);
|
|
|
|
|
|
|
|
|
|
string srch = "[collectiontype=";
|
|
|
|
|
int index = pathName.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
item.Name = pathName.Substring(0, index).Trim();
|
|
|
|
|
|
|
|
|
|
item.CollectionType = pathName.Substring(index + srch.Length).TrimEnd(']');
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 22:38:31 +02:00
|
|
|
|
base.SetInitialItemValues(item, args);
|
2012-08-18 21:38:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|