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

@ -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) public bool IsValidGDIPlusImage(string filename)
{ {
if (!CanUseGDIPlus())
{
return true;
}
try try
{ {
using (var bmp = new Bitmap(filename)) using (var bmp = new Bitmap(filename))
@ -120,7 +139,7 @@ namespace NzbDrone.Common.Disk
} }
catch (Exception ex) catch (Exception ex)
{ {
//_logger.Debug(ex, "Corrupted image found at: {0}. Redownloading...", filename); Logger.Debug(ex, "Corrupted image found at: {0}.", filename);
return false; return false;
} }
} }

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

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

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

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

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

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

Loading…
Cancel
Save