diff --git a/source/net/sourceforge/filebot/Analytics.java b/source/net/sourceforge/filebot/Analytics.java index 261f5a52..84bd6075 100644 --- a/source/net/sourceforge/filebot/Analytics.java +++ b/source/net/sourceforge/filebot/Analytics.java @@ -30,7 +30,7 @@ public class Analytics { private static boolean enabled = false; - public static synchronized JGoogleAnalyticsTracker getTracker() { + public static synchronized JGoogleAnalyticsTracker getTracker() throws Throwable { if (tracker != null) return tracker; @@ -66,10 +66,18 @@ public class Analytics { if (currentView == null) { // track application startup - getTracker().trackPageViewFromSearch(view, title, host, getJavaRuntimeIdentifier(), getDeploymentMethod()); + try { + getTracker().trackPageViewFromSearch(view, title, host, getJavaRuntimeIdentifier(), getDeploymentMethod()); + } catch (Throwable e) { + Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString()); + } } else { // track application state change - getTracker().trackPageViewFromReferrer(view, title, host, host, currentView); + try { + getTracker().trackPageViewFromReferrer(view, title, host, host, currentView); + } catch (Throwable e) { + Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString()); + } } currentView = view; @@ -85,7 +93,11 @@ public class Analytics { if (!enabled) return; - getTracker().trackEvent(normalize(category), normalize(action), normalize(label), value); + try { + getTracker().trackEvent(normalize(category), normalize(action), normalize(label), value); + } catch (Throwable e) { + Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString()); + } } @@ -134,28 +146,30 @@ public class Analytics { private static String getUserAgent() { - String wm = null; - String os = null; + // initialize with default values + String wm = System.getProperty("os.name"); + String os = System.getProperty("os.name") + " " + System.getProperty("os.version"); - if (Platform.isWindows()) { - wm = "Windows"; - os = "Windows NT " + System.getProperty("os.version"); - } else if (Platform.isX11()) { - wm = "X11"; - if (Platform.isLinux()) - os = "Linux " + System.getProperty("os.arch"); - else if (Platform.isSolaris()) - os = "SunOS " + System.getProperty("os.version"); - else if (Platform.isFreeBSD()) - os = "FreeBSD"; - else if (Platform.isOpenBSD()) - os = "OpenBSD"; - } else if (Platform.isMac()) { - wm = "Macintosh"; - os = System.getProperty("os.name"); - } else { - wm = System.getProperty("os.name"); - os = System.getProperty("os.name") + " " + System.getProperty("os.version"); + try { + if (Platform.isWindows()) { + wm = "Windows"; + os = "Windows NT " + System.getProperty("os.version"); + } else if (Platform.isX11()) { + wm = "X11"; + if (Platform.isLinux()) + os = "Linux " + System.getProperty("os.arch"); + else if (Platform.isSolaris()) + os = "SunOS " + System.getProperty("os.version"); + else if (Platform.isFreeBSD()) + os = "FreeBSD"; + else if (Platform.isOpenBSD()) + os = "OpenBSD"; + } else if (Platform.isMac()) { + wm = "Macintosh"; + os = System.getProperty("os.name"); + } + } catch (Throwable e) { + // ignore any Platform detection issues and especially ignore LinkageErrors that might occur on headless machines } return String.format("%s/%s (%s; U; %s; JRE %s)", getApplicationName(), getApplicationVersion(), wm, os, System.getProperty("java.version")); @@ -207,7 +221,6 @@ public class Analytics { return sb.toString(); } - private static final String VISITOR_ID = "visitorId"; private static final String TIMESTAMP_FIRST = "timestampFirst"; private static final String TIMESTAMP_LAST = "timestampLast"; @@ -252,7 +265,6 @@ public class Analytics { throw new UnsupportedOperationException(); } - static { // disable useless background logging, if it doesn't work it doesn't work, won't affect anything (putting it here works for Java 7) Logger.getLogger("com.dmurph.tracking").setLevel(Level.OFF); diff --git a/source/net/sourceforge/filebot/NativeRenameAction.java b/source/net/sourceforge/filebot/NativeRenameAction.java index 9fa06b98..f40c915e 100644 --- a/source/net/sourceforge/filebot/NativeRenameAction.java +++ b/source/net/sourceforge/filebot/NativeRenameAction.java @@ -66,7 +66,11 @@ public enum NativeRenameAction implements RenameAction { public static boolean isSupported() { - return Platform.isWindows(); + try { + return Platform.isWindows(); + } catch (Throwable e) { + return false; + } } } diff --git a/source/net/sourceforge/filebot/archive/SevenZipLoader.java b/source/net/sourceforge/filebot/archive/SevenZipLoader.java index 994e6531..8e661bdd 100644 --- a/source/net/sourceforge/filebot/archive/SevenZipLoader.java +++ b/source/net/sourceforge/filebot/archive/SevenZipLoader.java @@ -2,7 +2,7 @@ package net.sourceforge.filebot.archive; -import com.sun.jna.Platform; +import java.util.logging.Logger; import net.sf.sevenzipjbinding.IArchiveOpenCallback; import net.sf.sevenzipjbinding.IInStream; @@ -10,6 +10,8 @@ import net.sf.sevenzipjbinding.ISevenZipInArchive; import net.sf.sevenzipjbinding.SevenZip; import net.sf.sevenzipjbinding.SevenZipNativeInitializationException; +import com.sun.jna.Platform; + public class SevenZipLoader { @@ -23,8 +25,12 @@ public class SevenZipLoader { // initialize 7z-JBinding native libs try { - if (Platform.isWindows()) { - System.loadLibrary(Platform.is64Bit() ? "libgcc_s_sjlj-1" : "mingwm10"); + try { + if (Platform.isWindows()) { + System.loadLibrary(Platform.is64Bit() ? "libgcc_s_sjlj-1" : "mingwm10"); + } + } catch (Throwable e) { + Logger.getLogger(SevenZipLoader.class.getName()).warning("Failed to preload library: " + e); } System.loadLibrary("7-Zip-JBinding"); diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 7b1d98b4..e803f6e2 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -119,11 +119,11 @@ def XML(bc) { // Shell helper -import static com.sun.jna.Platform.* +import com.sun.jna.Platform def execute(Object... args) { def cmd = args.toList()*.toString() - if (isWindows()) { + if (tryQuietly{ Platform.isWindows() }) { // normalize file separator for windows and run with cmd so any executable in PATH will just work cmd = ['cmd', '/c'] + cmd } diff --git a/source/net/sourceforge/filebot/mediainfo/MediaInfo.java b/source/net/sourceforge/filebot/mediainfo/MediaInfo.java index fbba9e90..c3eb6113 100644 --- a/source/net/sourceforge/filebot/mediainfo/MediaInfo.java +++ b/source/net/sourceforge/filebot/mediainfo/MediaInfo.java @@ -21,15 +21,15 @@ import com.sun.jna.WString; public class MediaInfo implements Closeable { static { - // libmediainfo for linux depends on libzen - if (Platform.isLinux()) { - try { + try { + // libmediainfo for linux depends on libzen + if (Platform.isLinux()) { // We need to load dependencies first, because we know where our native libs are (e.g. Java Web Start Cache). // If we do not, the system will look for dependencies, but only in the library path. NativeLibrary.getInstance("zen"); - } catch (LinkageError e) { - Logger.getLogger(MediaInfo.class.getName()).warning("Failed to preload libzen"); } + } catch (Throwable e) { + Logger.getLogger(MediaInfo.class.getName()).warning("Failed to preload libzen"); } }