From b093be3f4e16ebd2dcbb286f57aca4ec74be0b6f Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 5 Nov 2016 22:17:08 +0100 Subject: [PATCH] Added additional gdiplus check. --- .../MediaCover/GdiPlusInterop.cs | 48 +++++++++++++++++++ src/NzbDrone.Core/MediaCover/ImageResizer.cs | 2 + src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 3 files changed, 51 insertions(+) create mode 100644 src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs diff --git a/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs b/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs new file mode 100644 index 000000000..36c5a65eb --- /dev/null +++ b/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Core.MediaCover +{ + public static class GdiPlusInterop + { + private static Exception _gdiPlusException; + + static GdiPlusInterop() + { + TestLibrary(); + } + + private static void TestLibrary() + { + if (OsInfo.IsWindows) + { + return; + } + + try + { + // We use StringFormat as test coz it gets properly cleaned up by the finalizer even if gdiplus is absent and is relatively non-invasive. + var strFormat = new StringFormat(); + + strFormat.Dispose(); + } + catch (Exception ex) + { + _gdiPlusException = ex; + } + } + + public static void CheckGdiPlus() + { + if (_gdiPlusException != null) + { + throw new DllNotFoundException("Couldn't load GDIPlus library", _gdiPlusException); + } + } + } +} diff --git a/src/NzbDrone.Core/MediaCover/ImageResizer.cs b/src/NzbDrone.Core/MediaCover/ImageResizer.cs index 0466c0361..9a75065ff 100644 --- a/src/NzbDrone.Core/MediaCover/ImageResizer.cs +++ b/src/NzbDrone.Core/MediaCover/ImageResizer.cs @@ -24,6 +24,8 @@ namespace NzbDrone.Core.MediaCover { try { + GdiPlusInterop.CheckGdiPlus(); + using (var sourceStream = _diskProvider.OpenReadStream(source)) { using (var outputStream = _diskProvider.OpenWriteStream(destination)) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 553e6b41a..d427f229e 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -686,6 +686,7 @@ +