Skip to content

Commit

Permalink
get rid of silent failure
Browse files Browse the repository at this point in the history
  • Loading branch information
matgr1 committed Sep 10, 2016
1 parent 1c6c7e9 commit 226f212
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
18 changes: 2 additions & 16 deletions src/Library/Classes/FreeImageEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ public static class FreeImageEngine

static FreeImageEngine()
{
// Check if FreeImage.dll is present and cancel setting the callbackfuntion if not
if (!IsAvailable)
{
return;
}
// TODO: try to take this out of the static constructor...
FreeImage.ValidateAvailability();

// Create a delegate (function pointer) to 'OnMessage'
outputMessageFunction = new OutputMessageFunction(OnMessage);
Expand All @@ -47,17 +44,6 @@ private static void OnMessage(FREE_IMAGE_FORMAT fif, string message)
}
}

/// <summary>
/// Gets a value indicating if the FreeImage DLL is available or not.
/// </summary>
public static bool IsAvailable
{
get
{
return FreeImage.IsAvailable();
}
}

/// <summary>
/// Internal errors in FreeImage generate a logstring that can be
/// captured by this event.
Expand Down
32 changes: 8 additions & 24 deletions src/Library/FreeImageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,16 @@ public static Version GetNativeVersion()
/// Further more must both libraries, including the program itself,
/// be the same architecture (x86 or x64).
/// </remarks>
public static bool IsAvailable()
public static void ValidateAvailability()
{
try
{
// Call a static fast executing function
Version nativeVersion = new Version(GetVersion());
Version wrapperVersion = GetWrapperVersion();
// No exception thrown, the library seems to be present
return
(nativeVersion.Major > wrapperVersion.Major) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build));
}
catch (DllNotFoundException)
{
return false;
}
#if NET462 || NET461 || NET46 || NET452 || NET451 || NET45 || NET40 || NET35 || NET20
catch (EntryPointNotFoundException)
{
return false;
}
#endif
catch (BadImageFormatException)
Version nativeVersion = new Version(GetVersion());
Version wrapperVersion = GetWrapperVersion();

if (false == ((nativeVersion.Major > wrapperVersion.Major) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) ||
((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build))))
{
return false;
throw new InvalidOperationException("Version mismatch");
}
}

Expand Down

0 comments on commit 226f212

Please sign in to comment.