Fix regression for missing libgdiplus (#1073)

* Fix regression for missing libgdiplus

Add back error handling for systems where libgdiplus is not available. Should fix #1065

* Create GdiPlusInterop.cs

* Update DiskProviderBase.cs

* Update ImageResizer.cs

* Delete GdiPlusInterop.cs

* Update NzbDrone.Core.csproj

* Update NzbDrone.Common.csproj

* Update DiskProviderBase.cs

* Update IDiskProvider.cs

* Update ImageResizer.cs

* Update DiskProviderBase.cs

* Update IDiskProvider.cs

* Update ImageResizer.cs

This is really ugly... :(

* Update ImageResizer.cs

Never written C# before

* Update ImageResizerFixture.cs

* Fix test
This commit is contained in:
SWu 2017-03-09 13:11:41 -05:00 committed by Devin Buhl
parent 3d9fd3ff25
commit 51e0cdf982
7 changed files with 35 additions and 7 deletions

View File

@ -108,9 +108,28 @@ namespace NzbDrone.Common.Disk
}
}
}
public bool CanUseGDIPlus()
{
try
{
GdiPlusInterop.CheckGdiPlus();
return true;
}
catch (DllNotFoundException ex)
{
Logger.Trace(ex, "System does not have libgdiplus.");
return false;
}
}
public bool IsValidGDIPlusImage(string filename)
{
if (!CanUseGDIPlus())
{
return true;
}
try
{
using (var bmp = new Bitmap(filename))
@ -120,7 +139,7 @@ namespace NzbDrone.Common.Disk
}
catch (Exception ex)
{
//_logger.Debug(ex, "Corrupted image found at: {0}. Redownloading...", filename);
Logger.Debug(ex, "Corrupted image found at: {0}.", filename);
return false;
}
}

View File

@ -2,7 +2,7 @@
using System.Drawing;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Core.MediaCover
namespace NzbDrone.Common.Disk
{
public static class GdiPlusInterop
{

View File

@ -19,6 +19,7 @@ namespace NzbDrone.Common.Disk
bool FolderExists(string path);
bool FileExists(string path);
bool FileExists(string path, StringComparison stringComparison);
bool CanUseGDIPlus();
bool IsValidGDIPlusImage(string path);
bool FolderWritable(string path);
string[] GetDirectories(string path);

View File

@ -90,6 +90,7 @@
<Compile Include="Disk\FileSystemModel.cs" />
<Compile Include="Disk\FileSystemResult.cs" />
<Compile Include="Extensions\DictionaryExtensions.cs" />
<Compile Include="Disk\GdiPlusInterop.cs" />
<Compile Include="Disk\OsPath.cs" />
<Compile Include="Disk\DiskProviderBase.cs" />
<Compile Include="Disk\IDiskProvider.cs" />
@ -258,4 +259,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@ -30,6 +30,10 @@ namespace NzbDrone.Core.Test.MediaCoverTests
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.DeleteFile(It.IsAny<string>()))
.Callback<string>(s => File.Delete(s));
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.CanUseGDIPlus())
.Returns(true);
}
[Test]
@ -64,4 +68,4 @@ namespace NzbDrone.Core.Test.MediaCoverTests
File.Exists(resizedFile).Should().BeFalse();
}
}
}
}

View File

@ -1,4 +1,5 @@
using ImageResizer;
using System;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.MediaCover
@ -21,7 +22,10 @@ namespace NzbDrone.Core.MediaCover
{
try
{
GdiPlusInterop.CheckGdiPlus();
if (!_diskProvider.CanUseGDIPlus())
{
throw new Exception("Can't resize without libgdiplus.");
}
using (var sourceStream = _diskProvider.OpenReadStream(source))
{

View File

@ -780,7 +780,6 @@
<Compile Include="Lifecycle\Commands\ShutdownCommand.cs" />
<Compile Include="Lifecycle\LifecycleService.cs" />
<Compile Include="MediaCover\CoverAlreadyExistsSpecification.cs" />
<Compile Include="MediaCover\GdiPlusInterop.cs" />
<Compile Include="MediaCover\MediaCover.cs" />
<Compile Include="MediaCover\ImageResizer.cs" />
<Compile Include="MediaCover\MediaCoverService.cs" />
@ -1341,4 +1340,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>