VirtualFolderResolver.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.ComponentModel.Composition;
  2. using System.IO;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Controller.Resolvers
  6. {
  7. [Export(typeof(IBaseItemResolver))]
  8. public class VirtualFolderResolver : BaseFolderResolver<VirtualFolder>
  9. {
  10. public override ResolverPriority Priority
  11. {
  12. get { return ResolverPriority.Third; }
  13. }
  14. protected override VirtualFolder Resolve(ItemResolveEventArgs args)
  15. {
  16. if (args.IsDirectory && args.Parent != null && args.Parent.IsRoot)
  17. {
  18. return new VirtualFolder();
  19. }
  20. return null;
  21. }
  22. protected override void SetInitialItemValues(VirtualFolder item, ItemResolveEventArgs args)
  23. {
  24. // Set the name initially by stripping off the [CollectionType=...]
  25. // The name can always be overridden later by folder.xml
  26. string pathName = Path.GetFileNameWithoutExtension(args.Path);
  27. string srch = "[collectiontype=";
  28. int index = pathName.IndexOf(srch, System.StringComparison.OrdinalIgnoreCase);
  29. if (index != -1)
  30. {
  31. item.Name = pathName.Substring(0, index).Trim();
  32. item.CollectionType = pathName.Substring(index + srch.Length).TrimEnd(']');
  33. }
  34. base.SetInitialItemValues(item, args);
  35. }
  36. }
  37. }