Commit 4b7c1b81 authored by Petri Hintukainen's avatar Petri Hintukainen

Add native method for listing files in BD-ROM directory

parent 19ac023b
......@@ -244,7 +244,21 @@ public abstract class BDFileSystem extends FileSystem {
}
public String[] list(File f) {
return fs.list(f);
String path = f.getPath();
String root = System.getProperty("bluray.vfs.root");
if (root == null || !path.startsWith(root)) {
/* not inside VFS */
return fs.list(f);
}
/* path is inside VFS */
/* EX. HOSTEL_2 lists files in BD-ROM */
int rootLength = root.length();
path = path.substring(rootLength);
String[] names = org.videolan.Libbluray.listBdFiles(path, false);
return names;
}
public boolean createDirectory(File f) {
......
......@@ -327,6 +327,10 @@ public class Libbluray {
return cacheBdRomFileN(nativePointer, path, cachePath) == 0;
}
public static String[] listBdFiles(String path, boolean onlyBdRom) {
return listBdFilesN(nativePointer, path, onlyBdRom);
}
public static void updateGraphic(int width, int height, int[] rgbArray) {
updateGraphicN(nativePointer, width, height, rgbArray,
0, 0, width - 1, height - 1);
......@@ -544,6 +548,7 @@ public class Libbluray {
private static native int setVirtualPackageN(long np, String vpPath, boolean psrBackup);
private static native int readPSRN(long np, int num);
private static native int cacheBdRomFileN(long np, String path, String cachePath);
private static native String[] listBdFilesN(long np, String path, boolean onlyBdRom);
private static native Bdjo getBdjoN(long np, String name);
private static native void updateGraphicN(long np, int width, int height, int[] rgbArray,
int x0, int y0, int x1, int y1);
......
......@@ -34,7 +34,9 @@
#include "file/file.h"
#include "util/logging.h"
#include "util/macro.h"
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
......@@ -358,6 +360,74 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_cacheBdRomFileN(JNIEnv * env,
return result;
}
JNIEXPORT jobjectArray JNICALL Java_org_videolan_Libbluray_listBdFilesN(JNIEnv * env,
jclass cls, jlong np, jstring jpath,
jboolean onlyBdRom) {
BLURAY *bd = (BLURAY*)(intptr_t)np;
BD_DISC *disc = bd_get_disc(bd);
const char *path = (*env)->GetStringUTFChars(env, jpath, NULL);
if (!path) {
BD_DEBUG(DBG_JNI | DBG_CRIT, "listBdFilesN() failed: no path\n");
return NULL;
}
BD_DEBUG(DBG_JNI, "listBdFilesN(%s)\n", path);
/* open directory stream */
BD_DIR_H *dp;
if (onlyBdRom) {
dp = disc_open_bdrom_dir(disc, path);
} else {
dp = disc_open_dir(disc, path);
}
if (!dp) {
BD_DEBUG(DBG_JNI | DBG_CRIT, "failed opening directory %s\n", path);
(*env)->ReleaseStringUTFChars(env, jpath, path);
return NULL;
}
(*env)->ReleaseStringUTFChars(env, jpath, path);
/* count files and create java strings (java array size must be known when it is created) */
jstring *files = NULL;
unsigned count = 0;
unsigned allocated = 0;
BD_DIRENT ent;
while (!dir_read(dp, &ent)) {
if (strcmp(ent.d_name, ".") && strcmp(ent.d_name, "..")) {
if (allocated <= count) {
allocated += 512;
jstring *tmp = realloc(files, sizeof(*files) * allocated);
if (!tmp) {
BD_DEBUG(DBG_JNI | DBG_CRIT, "failed allocating memory for %u directory entries\n", allocated);
break;
}
files = tmp;
}
files[count] = (*env)->NewStringUTF(env, ent.d_name);
count++;
}
}
dir_close(dp);
/* allocate java array */
jobjectArray arr = bdj_make_array(env, "java/lang/String", count);
if (!arr) {
BD_DEBUG(DBG_JNI | DBG_CRIT, "failed creating array [%d]\n", count);
} else {
/* populate files to array */
unsigned ii;
for (ii = 0; ii < count; ii++) {
(*env)->SetObjectArrayElement(env, arr, ii, files[ii]);
}
}
X_FREE(files);
return arr;
}
JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getBdjoN(JNIEnv * env,
jclass cls, jlong np, jstring jfile) {
......@@ -608,6 +678,11 @@ Java_org_videolan_Libbluray_methods[] =
CC("(JLjava/lang/String;Ljava/lang/String;)I"),
VC(Java_org_videolan_Libbluray_cacheBdRomFileN),
},
{
CC("listBdFilesN"),
CC("(JLjava/lang/String;Z)[Ljava/lang/String;"),
VC(Java_org_videolan_Libbluray_listBdFilesN),
},
{
CC("getBdjoN"),
CC("(JLjava/lang/String;)Lorg/videolan/bdjo/Bdjo;"),
......
......@@ -228,6 +228,15 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readPSRN
JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_cacheBdRomFileN
(JNIEnv *, jclass, jlong, jstring, jstring);
/*
* Class: org_videolan_Libbluray
* Method: listBdFilesN
* Signature: (JLjava/lang/String;Z)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_org_videolan_Libbluray_listBdFilesN(JNIEnv * env,
jclass cls, jlong np, jstring jpath,
jboolean onlyBdRom);
/*
* Class: org_videolan_Libbluray
* Method: getBdjoN
......
......@@ -294,6 +294,11 @@ const char *disc_volume_id(BD_DISC *p)
return p ? p->udf_volid : NULL;
}
BD_DIR_H *disc_open_bdrom_dir(BD_DISC *p, const char *rel_path)
{
return p->pf_dir_open_bdrom(p->fs_handle, rel_path);
}
/*
* VFS
*/
......
......@@ -66,6 +66,9 @@ BD_PRIVATE void disc_update(BD_DISC *disc, const char *overlay_root);
BD_PRIVATE int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_path);
/* open BD-ROM directory (relative to disc root) */
BD_PRIVATE struct bd_dir_s *disc_open_bdrom_dir(BD_DISC *disc, const char *path);
/*
* m2ts stream interface
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment