2013-10-31 14:03:23 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-08-13 14:51:26 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-10-28 14:56:57 +00:00
|
|
|
|
using MediaBrowser.Providers.Savers;
|
2013-08-13 14:51:26 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Games
|
|
|
|
|
{
|
|
|
|
|
public class GameProviderFromXml : BaseMetadataProvider
|
|
|
|
|
{
|
2013-10-31 14:03:23 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
2013-08-13 14:51:26 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logManager"></param>
|
|
|
|
|
/// <param name="configurationManager"></param>
|
2013-10-31 14:03:23 +00:00
|
|
|
|
public GameProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem)
|
2013-08-13 14:51:26 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
2013-10-31 14:03:23 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2013-08-13 14:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is Game;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-01 18:24:27 +00:00
|
|
|
|
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
2013-08-13 14:51:26 +00:00
|
|
|
|
{
|
2013-10-01 18:24:27 +00:00
|
|
|
|
var savePath = GameXmlSaver.GetGameSavePath(item);
|
|
|
|
|
|
|
|
|
|
var xml = item.ResolveArgs.GetMetaFileByPath(savePath) ?? new FileInfo(savePath);
|
|
|
|
|
|
|
|
|
|
if (!xml.Exists)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 15:59:40 +00:00
|
|
|
|
return _fileSystem.GetLastWriteTimeUtc(xml) > item.DateLastSaved;
|
2013-08-13 14:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="force"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return Fetch((Game)item, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="game"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<bool> Fetch(Game game, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-10-01 18:24:27 +00:00
|
|
|
|
var metaFile = GameXmlSaver.GetGameSavePath(game);
|
2013-08-13 14:51:26 +00:00
|
|
|
|
|
2013-10-10 16:55:07 +00:00
|
|
|
|
if (File.Exists(metaFile))
|
2013-10-01 18:24:27 +00:00
|
|
|
|
{
|
2013-10-10 16:55:07 +00:00
|
|
|
|
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-10-28 14:56:57 +00:00
|
|
|
|
new GameXmlParser(Logger).Fetch(game, metaFile, cancellationToken);
|
2013-10-10 16:55:07 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
XmlParsingResourcePool.Release();
|
|
|
|
|
}
|
2013-08-13 14:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetLastRefreshed(game, DateTime.UtcNow);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
2013-10-03 14:14:40 +00:00
|
|
|
|
get { return MetadataProviderPriority.Second; }
|
2013-08-13 14:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|