mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
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:
parent
3d9fd3ff25
commit
51e0cdf982
@ -108,9 +108,28 @@ public bool FileExists(string path, StringComparison stringComparison)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public bool IsValidGDIPlusImage(string filename)
|
||||
}
|
||||
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 @@ public interface IDiskProvider
|
||||
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" />
|
||||
@ -258,4 +259,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -30,6 +30,10 @@ public void SetUp()
|
||||
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 @@ public void should_delete_file_if_failed()
|
||||
File.Exists(resizedFile).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ImageResizer;
|
||||
using System;
|
||||
using NzbDrone.Common.Disk;
|
||||
|
||||
namespace NzbDrone.Core.MediaCover
|
||||
@ -21,7 +22,10 @@ public void Resize(string source, string destination, int height)
|
||||
{
|
||||
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" />
|
||||
@ -1341,4 +1340,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user