diff --git a/source/net/sourceforge/filebot/gio/GIOLibrary.java b/source/net/sourceforge/filebot/gio/GIOLibrary.java index 2a788117..0bb376cd 100644 --- a/source/net/sourceforge/filebot/gio/GIOLibrary.java +++ b/source/net/sourceforge/filebot/gio/GIOLibrary.java @@ -3,15 +3,11 @@ package net.sourceforge.filebot.gio; import com.sun.jna.Library; -import com.sun.jna.Native; import com.sun.jna.Pointer; interface GIOLibrary extends Library { - GIOLibrary INSTANCE = (GIOLibrary) Native.loadLibrary("gio-2.0", GIOLibrary.class); - - void g_type_init(); diff --git a/source/net/sourceforge/filebot/gio/GVFS.java b/source/net/sourceforge/filebot/gio/GVFS.java index d1c88a31..d0d8ac65 100644 --- a/source/net/sourceforge/filebot/gio/GVFS.java +++ b/source/net/sourceforge/filebot/gio/GVFS.java @@ -5,26 +5,35 @@ package net.sourceforge.filebot.gio; import java.io.File; import java.net.URI; +import com.sun.jna.Native; import com.sun.jna.Pointer; public class GVFS { + private static GIOLibrary lib; private static Pointer gvfs; + private synchronized static GIOLibrary getLibrary() { + if (lib == null) { + lib = (GIOLibrary) Native.loadLibrary("gio-2.0", GIOLibrary.class); + } + return lib; + } + + public synchronized static Pointer getDefaultVFS() { if (gvfs == null) { - GIOLibrary.INSTANCE.g_type_init(); - gvfs = GIOLibrary.INSTANCE.g_vfs_get_default(); + gvfs = getLibrary().g_vfs_get_default(); } return gvfs; } public static File getPathForURI(URI uri) { - Pointer gfile = GIOLibrary.INSTANCE.g_vfs_get_file_for_uri(getDefaultVFS(), uri.toString()); - Pointer chars = GIOLibrary.INSTANCE.g_file_get_path(gfile); + Pointer gfile = getLibrary().g_vfs_get_file_for_uri(getDefaultVFS(), uri.toString()); + Pointer chars = getLibrary().g_file_get_path(gfile); try { if (chars != null) @@ -32,8 +41,8 @@ public class GVFS { else return null; } finally { - GIOLibrary.INSTANCE.g_object_unref(gfile); - GIOLibrary.INSTANCE.g_free(chars); + getLibrary().g_object_unref(gfile); + getLibrary().g_free(chars); } }