2012-08-18 19:38:27 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
2012-08-23 20:51:10 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2012-08-18 19:38:27 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
|
|
|
|
{
|
|
|
|
|
[Export(typeof(IBaseItemResolver))]
|
|
|
|
|
public class VirtualFolderResolver : BaseFolderResolver<VirtualFolder>
|
|
|
|
|
{
|
2012-08-20 15:55:05 +00:00
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return ResolverPriority.Third; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-18 19:38:27 +00:00
|
|
|
|
protected override VirtualFolder Resolve(ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-08-21 14:42:40 +00:00
|
|
|
|
if (args.IsDirectory && args.Parent != null && args.Parent.IsRoot)
|
2012-08-18 19:38:27 +00:00
|
|
|
|
{
|
|
|
|
|
return new VirtualFolder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 20:38:31 +00:00
|
|
|
|
protected override void SetInitialItemValues(VirtualFolder item, ItemResolveEventArgs args)
|
2012-08-18 19:38:27 +00: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 20:38:31 +00:00
|
|
|
|
base.SetInitialItemValues(item, args);
|
2012-08-18 19:38:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|