Refactor GVFS (don't require libgio)
This commit is contained in:
parent
86c8f381a8
commit
a5eefa00b2
14
source/net/filebot/gio/GVFS.java
Normal file
14
source/net/filebot/gio/GVFS.java
Normal file
@ -0,0 +1,14 @@
|
||||
package net.filebot.gio;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
public interface GVFS {
|
||||
|
||||
File getPathForURI(URI uri);
|
||||
|
||||
public static GVFS getDefaultVFS() {
|
||||
return new PlatformGVFS();
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +1,21 @@
|
||||
|
||||
package net.filebot.gio;
|
||||
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
|
||||
interface GIOLibrary extends Library {
|
||||
interface LibGIO extends Library {
|
||||
|
||||
void g_type_init();
|
||||
|
||||
|
||||
Pointer g_vfs_get_default();
|
||||
|
||||
|
||||
Pointer g_vfs_get_file_for_uri(Pointer gvfs, String uri);
|
||||
|
||||
|
||||
Pointer g_file_get_path(Pointer gfile);
|
||||
|
||||
|
||||
void g_free(Pointer gpointer);
|
||||
|
||||
|
||||
void g_object_unref(Pointer gobject);
|
||||
|
||||
}
|
||||
|
@ -1,39 +1,20 @@
|
||||
|
||||
package net.filebot.gio;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
public class NativeGVFS implements GVFS {
|
||||
|
||||
public class GVFS {
|
||||
private static final LibGIO lib_gio = (LibGIO) Native.loadLibrary("gio-2.0", LibGIO.class);
|
||||
private static final Pointer gvfs = lib_gio.g_vfs_get_default();
|
||||
|
||||
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) {
|
||||
gvfs = getLibrary().g_vfs_get_default();
|
||||
}
|
||||
return gvfs;
|
||||
}
|
||||
|
||||
|
||||
public static File getPathForURI(URI uri) {
|
||||
Pointer gfile = getLibrary().g_vfs_get_file_for_uri(getDefaultVFS(), uri.toString());
|
||||
Pointer chars = getLibrary().g_file_get_path(gfile);
|
||||
public File getPathForURI(URI uri) {
|
||||
Pointer gfile = lib_gio.g_vfs_get_file_for_uri(gvfs, uri.toString());
|
||||
Pointer chars = lib_gio.g_file_get_path(gfile);
|
||||
|
||||
try {
|
||||
if (chars != null)
|
||||
@ -41,8 +22,8 @@ public class GVFS {
|
||||
else
|
||||
return null;
|
||||
} finally {
|
||||
getLibrary().g_object_unref(gfile);
|
||||
getLibrary().g_free(chars);
|
||||
lib_gio.g_object_unref(gfile);
|
||||
lib_gio.g_free(chars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class FileTransferable implements Transferable {
|
||||
// try handle other GVFS URI schemes
|
||||
try {
|
||||
if (useGVFS()) {
|
||||
file = GVFS.getPathForURI(uri);
|
||||
file = GVFS.getDefaultVFS().getPathForURI(uri);
|
||||
}
|
||||
} catch (LinkageError error) {
|
||||
debug.log(Level.WARNING, "Unable to resolve GVFS URI", error);
|
||||
|
Loading…
Reference in New Issue
Block a user