Update JNI and catch the new exception thrown by an invalid ZIM

This commit is contained in:
mhutti1 2018-02-02 00:20:45 +00:00 committed by Isaac Hutt
parent 2f93ebf800
commit 41c0bb84c4
2 changed files with 12 additions and 6 deletions

View File

@ -34,7 +34,7 @@ dependencies {
// Get kiwixlib online if it is not populated locally // Get kiwixlib online if it is not populated locally
if (file("../kiwixlib/src/main").list().length == 1) { if (file("../kiwixlib/src/main").list().length == 1) {
implementation 'org.kiwix.kiwixlib:kiwixlib:1.0.6' implementation 'org.kiwix.kiwixlib:kiwixlib:1.0.8'
} else { } else {
implementation project(':kiwixlib') implementation project(':kiwixlib')
archs = file("../kiwixlib/src/main/jniLibs").list() archs = file("../kiwixlib/src/main/jniLibs").list()

View File

@ -31,6 +31,7 @@ import android.webkit.MimeTypeMap;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import org.kiwix.kiwixlib.JNIKiwix; import org.kiwix.kiwixlib.JNIKiwix;
import org.kiwix.kiwixlib.JNIKiwixException;
import org.kiwix.kiwixlib.JNIKiwixInt; import org.kiwix.kiwixlib.JNIKiwixInt;
import org.kiwix.kiwixlib.JNIKiwixReader; import org.kiwix.kiwixlib.JNIKiwixReader;
import org.kiwix.kiwixlib.JNIKiwixSearcher; import org.kiwix.kiwixlib.JNIKiwixSearcher;
@ -110,19 +111,24 @@ public class ZimContentProvider extends ContentProvider {
} }
public synchronized static String setZimFile(String fileName) { public synchronized static String setZimFile(String fileName) {
JNIKiwixReader reader = new JNIKiwixReader(fileName); if (!new File(fileName).exists()) {
if (!new File(fileName).exists() || reader == null) { Log.e(TAG_KIWIX, "Unable to find the ZIM file " + fileName);
Log.e(TAG_KIWIX, "Unable to open the ZIM file " + fileName);
zimFileName = null; zimFileName = null;
} else { return zimFileName;
}
try {
JNIKiwixReader reader = new JNIKiwixReader(fileName);
Log.i(TAG_KIWIX, "Opening ZIM file " + fileName); Log.i(TAG_KIWIX, "Opening ZIM file " + fileName);
if(!listedEntries.contains(reader.getId())) { if(!listedEntries.contains(reader.getId())) {
listedEntries.add(reader.getId()); listedEntries.add(reader.getId());
jniSearcher.addKiwixReader(reader); jniSearcher.addKiwixReader(reader);
currentJNIReader = reader;
} }
zimFileName = fileName; zimFileName = fileName;
} catch (JNIKiwixException e) {
Log.e(TAG_KIWIX, "Unable to open the ZIM file " + fileName);
zimFileName = null;
} }
currentJNIReader = reader;
return zimFileName; return zimFileName;
} }