mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
+ load the ICU data file dynamically
This commit is contained in:
parent
a023c3986a
commit
d6964d7954
@ -251,7 +251,7 @@ if COMPILE_LIBICU:
|
||||
if (not os.path.exists(ICU_TMP_TARGET)):
|
||||
os.mkdir(ICU_TMP_TARGET);
|
||||
os.chdir(ICU_TMP_HOST)
|
||||
syscall(LIBICU_SRC + '/configure', shell=True)
|
||||
syscall(LIBICU_SRC + '/configure --with-data-packaging=archive', shell=True)
|
||||
syscall('make', shell=True)
|
||||
os.chdir(os.getcwd())
|
||||
|
||||
@ -302,6 +302,12 @@ for arch in ARCHS:
|
||||
syscall('ln -sf %(src)s %(dest)s/'
|
||||
% {'src': ln_src, 'dest': dest})
|
||||
|
||||
# add a link to icudt49l.dat
|
||||
ln_src = LIBICU_SRC + '/data/in/icudt49l.dat'
|
||||
dest = os.path.join(os.path.dirname(CURRENT_PATH), 'android', 'assets')
|
||||
syscall('ln -sf %(src)s %(dest)s/'
|
||||
% {'src': ln_src, 'dest': dest})
|
||||
|
||||
# check that the step went well
|
||||
if CREATE_TOOLCHAIN or COMPILE_LIBLZMA or COMPILE_LIBZIM or \
|
||||
COMPILE_LIBKIWIX or STRIP_LIBKIWIX:
|
||||
@ -356,7 +362,7 @@ for arch in ARCHS:
|
||||
# compile libicu.a, libicu.so
|
||||
os.chdir(ICU_TMP_TARGET)
|
||||
configure_cmd = ( LIBICU_SRC + '/configure --host=%(arch)s --enable-static '
|
||||
'--prefix=%(platform)s --with-cross-build=%(icu)s --disable-shared --enable-static '
|
||||
'--prefix=%(platform)s --with-cross-build=%(icu)s --disable-shared --with-data-packaging=archive '
|
||||
% {'arch': arch_full, 'platform': platform, 'icu': ICU_TMP_HOST})
|
||||
|
||||
if COMPILE_LIBICU:
|
||||
|
13
kiwix.c
13
kiwix.c
@ -7,6 +7,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "unicode/putil.h"
|
||||
#include <kiwix/reader.h>
|
||||
|
||||
/* global variables */
|
||||
@ -274,3 +275,15 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getRandomPage
|
||||
return retVal;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_setDataDirectory
|
||||
(JNIEnv *env, jobject obj, jstring dirStr) {
|
||||
std::string cPath = jni2c(dirStr, env);
|
||||
|
||||
pthread_mutex_lock(&readerLock);
|
||||
try {
|
||||
u_setDataDirectory(cPath.c_str());
|
||||
} catch (exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
pthread_mutex_unlock(&readerLock);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -38,6 +38,7 @@ public class JNIKiwix {
|
||||
public native boolean getArticleCount(JNIKiwixInt count);
|
||||
public native boolean getMediaCount(JNIKiwixInt count);
|
||||
public native boolean getRandomPage(JNIKiwixString url);
|
||||
public native void setDataDirectory(String icuDataDir);
|
||||
|
||||
static {
|
||||
System.loadLibrary("kiwix");
|
||||
|
@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
@ -28,8 +29,11 @@ import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class ZimContentProvider extends ContentProvider {
|
||||
@ -135,7 +139,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
jniKiwix = new JNIKiwix();
|
||||
|
||||
setIcuDataDirectory();
|
||||
return (true);
|
||||
}
|
||||
|
||||
@ -261,4 +265,41 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setIcuDataDirectory() {
|
||||
File workingDir = this.getContext().getFilesDir();
|
||||
String icuDirPath = loadICUData(this.getContext(), workingDir);
|
||||
|
||||
if(icuDirPath != null) {
|
||||
Log.d("kiwix", "Setting the ICU directory path to " + icuDirPath);
|
||||
jniKiwix.setDataDirectory(icuDirPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static String loadICUData(Context context, File workingDir) {
|
||||
String icuFileName = "icudt49l.dat";
|
||||
try {
|
||||
File icuDir = new File(workingDir, "icu");
|
||||
if(!icuDir.exists()) icuDir.mkdirs();
|
||||
File icuDataFile = new File(icuDir, icuFileName);
|
||||
if(!icuDataFile.exists()) {
|
||||
InputStream in = context.getAssets().open(icuFileName);
|
||||
OutputStream out = new FileOutputStream(icuDataFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
return icuDir.getAbsolutePath();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e("kiwix", "Error copying icu data file", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user