From 98fdd221ff14bbfca1f614f1b813452b2a785576 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 15 Nov 2011 02:50:48 +0000 Subject: [PATCH] * added info about required native lib arch to error msg if mediainfo native code can't be loaded --- .../filebot/mediainfo/MediaInfo.java | 12 ++++++++++-- .../filebot/mediainfo/MediaInfoException.java | 19 +++++++++++++++++++ .../filebot/ui/rename/BindingDialog.java | 5 +++-- .../filebot/web/SublightSubtitleClient.java | 3 --- .../filebot/web/SublightVideoHasher.java | 5 +++-- 5 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 source/net/sourceforge/filebot/mediainfo/MediaInfoException.java diff --git a/source/net/sourceforge/filebot/mediainfo/MediaInfo.java b/source/net/sourceforge/filebot/mediainfo/MediaInfo.java index 45707839..e9ab25f0 100644 --- a/source/net/sourceforge/filebot/mediainfo/MediaInfo.java +++ b/source/net/sourceforge/filebot/mediainfo/MediaInfo.java @@ -36,7 +36,11 @@ public class MediaInfo implements Closeable { public MediaInfo() { - handle = MediaInfoLibrary.INSTANCE.New(); + try { + handle = MediaInfoLibrary.INSTANCE.New(); + } catch (LinkageError e) { + throw new MediaInfoException(e); + } } @@ -236,7 +240,11 @@ public class MediaInfo implements Closeable { public static String staticOption(String option, String value) { - return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString(); + try { + return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString(); + } catch (LinkageError e) { + throw new MediaInfoException(e); + } } } diff --git a/source/net/sourceforge/filebot/mediainfo/MediaInfoException.java b/source/net/sourceforge/filebot/mediainfo/MediaInfoException.java new file mode 100644 index 00000000..61023fdb --- /dev/null +++ b/source/net/sourceforge/filebot/mediainfo/MediaInfoException.java @@ -0,0 +1,19 @@ + +package net.sourceforge.filebot.mediainfo; + + +import com.sun.jna.Platform; + + +public class MediaInfoException extends RuntimeException { + + public MediaInfoException(LinkageError e) { + this(String.format("Unable to load %d-bit native library 'mediainfo'", Platform.is64Bit() ? 64 : 32), e); + } + + + public MediaInfoException(String msg, Throwable e) { + super(msg, e); + } + +} diff --git a/source/net/sourceforge/filebot/ui/rename/BindingDialog.java b/source/net/sourceforge/filebot/ui/rename/BindingDialog.java index 88f8b9ee..8330cda3 100644 --- a/source/net/sourceforge/filebot/ui/rename/BindingDialog.java +++ b/source/net/sourceforge/filebot/ui/rename/BindingDialog.java @@ -58,6 +58,7 @@ import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.format.ExpressionFormat; import net.sourceforge.filebot.format.MediaBindingBean; import net.sourceforge.filebot.mediainfo.MediaInfo; +import net.sourceforge.filebot.mediainfo.MediaInfoException; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; import net.sourceforge.tuned.DefaultThreadFactory; import net.sourceforge.tuned.ui.LazyDocumentListener; @@ -297,8 +298,8 @@ class BindingDialog extends JDialog { mediaInfo.close(); } } - } catch (LinkageError e) { - UILogger.log(Level.SEVERE, "Unable to load native library 'mediainfo'", e); + } catch (MediaInfoException e) { + UILogger.log(Level.SEVERE, e.getMessage(), e); } // could not retrieve media info diff --git a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java index 03dd6a99..fa26c551 100644 --- a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java +++ b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java @@ -150,9 +150,6 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit }); } catch (IOException e) { Logger.getLogger(SublightSubtitleClient.class.getName()).log(Level.WARNING, "Error computing video hash: " + e.getMessage()); - } catch (LinkageError e) { - // MediaInfo native lib not available - throw new UnsupportedOperationException(e.getMessage(), e); } requests.add(i, request); diff --git a/source/net/sourceforge/filebot/web/SublightVideoHasher.java b/source/net/sourceforge/filebot/web/SublightVideoHasher.java index 0a2919f9..0b20c73e 100644 --- a/source/net/sourceforge/filebot/web/SublightVideoHasher.java +++ b/source/net/sourceforge/filebot/web/SublightVideoHasher.java @@ -15,6 +15,7 @@ import java.util.Formatter; import java.util.concurrent.TimeUnit; import net.sourceforge.filebot.mediainfo.MediaInfo; +import net.sourceforge.filebot.mediainfo.MediaInfoException; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; @@ -32,7 +33,7 @@ import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; */ public final class SublightVideoHasher { - public static String computeHash(File file) throws IOException, LinkageError { + public static String computeHash(File file) throws IOException, MediaInfoException { byte[][] hash = new byte[4][]; // 1 byte = 0 (reserved) @@ -79,7 +80,7 @@ public final class SublightVideoHasher { } - protected static long getDuration(File file, TimeUnit unit) throws IOException, LinkageError { + protected static long getDuration(File file, TimeUnit unit) throws IOException, MediaInfoException { MediaInfo mediaInfo = new MediaInfo(); if (!mediaInfo.open(file))