From 86c8f381a8f2c60d3e7f8b18ef9495abd762e590 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 12 Jul 2016 00:03:07 +0800 Subject: [PATCH] Refactor GVFS (don't require libgio) --- source/net/filebot/gio/LibC.java | 9 +++++++ .../gio/{GIOLibrary.java => LibGIO.java} | 0 .../gio/{GVFS.java => NativeGVFS.java} | 0 source/net/filebot/gio/PlatformGVFS.java | 25 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 source/net/filebot/gio/LibC.java rename source/net/filebot/gio/{GIOLibrary.java => LibGIO.java} (100%) rename source/net/filebot/gio/{GVFS.java => NativeGVFS.java} (100%) create mode 100644 source/net/filebot/gio/PlatformGVFS.java diff --git a/source/net/filebot/gio/LibC.java b/source/net/filebot/gio/LibC.java new file mode 100644 index 00000000..167ee15d --- /dev/null +++ b/source/net/filebot/gio/LibC.java @@ -0,0 +1,9 @@ +package net.filebot.gio; + +import com.sun.jna.Library; + +interface LibC extends Library { + + int getuid(); + +} diff --git a/source/net/filebot/gio/GIOLibrary.java b/source/net/filebot/gio/LibGIO.java similarity index 100% rename from source/net/filebot/gio/GIOLibrary.java rename to source/net/filebot/gio/LibGIO.java diff --git a/source/net/filebot/gio/GVFS.java b/source/net/filebot/gio/NativeGVFS.java similarity index 100% rename from source/net/filebot/gio/GVFS.java rename to source/net/filebot/gio/NativeGVFS.java diff --git a/source/net/filebot/gio/PlatformGVFS.java b/source/net/filebot/gio/PlatformGVFS.java new file mode 100644 index 00000000..3b09e45d --- /dev/null +++ b/source/net/filebot/gio/PlatformGVFS.java @@ -0,0 +1,25 @@ + +package net.filebot.gio; + +import java.io.File; +import java.net.URI; + +import com.sun.jna.Native; + +public class PlatformGVFS implements GVFS { + + private static final LibC lib_c = (LibC) Native.loadLibrary("c", LibC.class); + private static final String gvfs = "/run/user/" + lib_c.getuid() + "/gvfs/"; + + public File getPathForURI(URI uri) { + // e.g. smb://10.0.1.5/data/Movies/Avatar.mp4 -> /run/user/1000/gvfs/smb-share:server=10.0.1.5,share=data/Movies/Avatar.mp4 + + switch (uri.getScheme()) { + case "file": + return new File(uri); + default: + return new File(gvfs + uri.getScheme() + "-share:server=" + uri.getHost() + ",share=" + uri.getPath().substring(1)); + } + } + +}