2019-07-27 07:19:43 +00:00
|
|
|
using System;
|
2018-05-25 01:08:35 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2013-10-03 01:01:32 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.MediaCover
|
|
|
|
{
|
|
|
|
public interface ICoverExistsSpecification
|
|
|
|
{
|
2019-07-27 07:19:43 +00:00
|
|
|
bool AlreadyExists(DateTime? serverModifiedDate, long? serverContentLength, string localPath);
|
2013-10-03 01:01:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class CoverAlreadyExistsSpecification : ICoverExistsSpecification
|
|
|
|
{
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
|
2018-05-25 01:08:35 +00:00
|
|
|
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider)
|
2013-10-03 01:01:32 +00:00
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
}
|
|
|
|
|
2019-07-27 07:19:43 +00:00
|
|
|
public bool AlreadyExists(DateTime? serverModifiedDate, long? serverContentLength, string localPath)
|
2013-10-03 01:01:32 +00:00
|
|
|
{
|
2018-05-25 01:08:35 +00:00
|
|
|
if (!_diskProvider.FileExists(localPath))
|
2013-10-03 01:01:32 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-27 12:33:10 +00:00
|
|
|
if (serverContentLength.HasValue && serverContentLength.Value > 0)
|
2019-07-27 07:19:43 +00:00
|
|
|
{
|
2019-07-27 12:33:10 +00:00
|
|
|
var fileSize = _diskProvider.GetFileSize(localPath);
|
2019-07-27 07:19:43 +00:00
|
|
|
|
2019-07-27 12:33:10 +00:00
|
|
|
return fileSize == serverContentLength;
|
2019-07-27 07:19:43 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 12:33:10 +00:00
|
|
|
if (serverModifiedDate.HasValue)
|
2019-07-27 07:19:43 +00:00
|
|
|
{
|
2019-07-27 12:33:10 +00:00
|
|
|
DateTime? lastModifiedLocal = _diskProvider.FileGetLastWrite(localPath);
|
2019-07-27 07:19:43 +00:00
|
|
|
|
2019-07-27 12:33:10 +00:00
|
|
|
return lastModifiedLocal.Value.ToUniversalTime() == serverModifiedDate.Value.ToUniversalTime();
|
2019-07-27 07:19:43 +00:00
|
|
|
}
|
2018-05-25 01:08:35 +00:00
|
|
|
|
2019-07-27 07:19:43 +00:00
|
|
|
return false;
|
2013-10-03 01:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-25 01:08:35 +00:00
|
|
|
}
|