mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 08:18:52 -05:00
* avoid GVFS initialization issues
This commit is contained in:
parent
0c46748575
commit
94013e2366
@ -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();
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user