| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 | 
							- using MediaBrowser.Common.Extensions;
 
- using MediaBrowser.Controller.Configuration;
 
- using MediaBrowser.Controller.Entities;
 
- using MediaBrowser.Controller.IO;
 
- using MediaBrowser.Model.Logging;
 
- using System;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- namespace MediaBrowser.Controller.Providers
 
- {
 
-     /// <summary>
 
-     /// Provides images for generic types by looking for standard images in the IBN
 
-     /// </summary>
 
-     public class ImagesByNameProvider : ImageFromMediaLocationProvider
 
-     {
 
-         public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
 
-             : base(logManager, configurationManager)
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// Supportses the specified item.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 
-         public override bool Supports(BaseItem item)
 
-         {
 
-             //only run for these generic types since we are expensive in file i/o
 
-             return item is IndexFolder || item is BasePluginFolder || item is CollectionFolder;
 
-         }
 
-         /// <summary>
 
-         /// Gets the priority.
 
-         /// </summary>
 
-         /// <value>The priority.</value>
 
-         public override MetadataProviderPriority Priority
 
-         {
 
-             get
 
-             {
 
-                 return MetadataProviderPriority.Last;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Needses the refresh internal.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="providerInfo">The provider info.</param>
 
-         /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 
-         protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
 
-         {
 
-             // Force a refresh if the IBN path changed
 
-             if (providerInfo.Data != ConfigurationManager.ApplicationPaths.ItemsByNamePath.GetMD5())
 
-             {
 
-                 return true;
 
-             }
 
-             return base.NeedsRefreshInternal(item, providerInfo);
 
-         }
 
-         /// <summary>
 
-         /// Gets a value indicating whether [refresh on file system stamp change].
 
-         /// </summary>
 
-         /// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
 
-         protected override bool RefreshOnFileSystemStampChange
 
-         {
 
-             get
 
-             {
 
-                 return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Override this to return the date that should be compared to the last refresh date
 
-         /// to determine if this provider should be re-fetched.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <returns>DateTime.</returns>
 
-         protected override DateTime CompareDate(BaseItem item)
 
-         {
 
-             // If the IBN location exists return the last modified date of any file in it
 
-             var location = GetLocation(item);
 
-             if (!Directory.Exists(location))
 
-             {
 
-                 return DateTime.MinValue;
 
-             }
 
-             var files = new DirectoryInfo(location).EnumerateFiles().ToList();
 
-             if (files.Count == 0)
 
-             {
 
-                 return DateTime.MinValue;
 
-             }
 
-             return files.Select(f =>
 
-             {
 
-                 var lastWriteTime = FileSystem.GetLastWriteTimeUtc(f, Logger);
 
-                 var creationTime = FileSystem.GetCreationTimeUtc(f, Logger);
 
-                 return creationTime > lastWriteTime ? creationTime : lastWriteTime;
 
-             }).Max();
 
-         }
 
-         /// <summary>
 
-         /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="force">if set to <c>true</c> [force].</param>
 
-         /// <param name="cancellationToken">The cancellation token.</param>
 
-         /// <returns>Task{System.Boolean}.</returns>
 
-         public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
 
-         {
 
-             var result = await base.FetchAsync(item, force, cancellationToken).ConfigureAwait(false);
 
-             BaseProviderInfo data;
 
-             if (!item.ProviderData.TryGetValue(Id, out data))
 
-             {
 
-                 data = new BaseProviderInfo();
 
-                 item.ProviderData[Id] = data;
 
-             }
 
-             data.Data = ConfigurationManager.ApplicationPaths.ItemsByNamePath.GetMD5();
 
-             
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// Gets the location.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <returns>System.String.</returns>
 
-         protected string GetLocation(BaseItem item)
 
-         {
 
-             var name = FileSystem.GetValidFilename(item.Name);
 
-             return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name);
 
-         }
 
-         /// <summary>
 
-         /// Gets the image.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="filenameWithoutExtension">The filename without extension.</param>
 
-         /// <returns>FileSystemInfo.</returns>
 
-         protected override FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension)
 
-         {
 
-             var location = GetLocation(item);
 
-             var result = new FileInfo(Path.Combine(location, filenameWithoutExtension + ".png"));
 
-             if (!result.Exists)
 
-                 result = new FileInfo(Path.Combine(location, filenameWithoutExtension + ".jpg"));
 
-             if (result.Exists)
 
-             {
 
-                 return result;
 
-             }
 
-             return null;
 
-         }
 
-     }
 
- }
 
 
  |