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
pull/2/head
SWu 8 years ago committed by Devin Buhl
parent 3d9fd3ff25
commit 51e0cdf982

@ -109,8 +109,27 @@ 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;
}
}

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

@ -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);

@ -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" />

@ -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]

@ -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))
{

@ -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" />

Loading…
Cancel
Save