2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/platform/android/llapp_main.lua
chrox 34ea9ac574 add datastorage module to handle data directory on various platform
On kindle, kobo and pocketbook the data directory is the current
running directory but on Android the app is installed in system
defined location and users may have no access to that location.
The same circumstances should be true for the upcoming Koreader for
Ubuntu touch, so the data directory (in which tessdata, dictionaries,
global settings, persistant defaults and probably history data are
stored) could be stored in another place.
2015-06-15 16:56:27 +08:00

44 lines
1.1 KiB
Lua

local A = require("android")
A.dl.library_path = A.dl.library_path .. ":" .. A.dir .. "/libs"
local ffi = require("ffi")
ffi.cdef[[
char *getenv(const char *name);
int putenv(const char *envvar);
]]
-- check uri of the intent that starts this application
local file = A.jni:context(A.app.activity.vm, function(JNI)
local uri = JNI:callObjectMethod(
JNI:callObjectMethod(
A.app.activity.clazz,
"getIntent",
"()Landroid/content/Intent;"
),
"getData",
"()Landroid/net/Uri;"
)
if uri ~= nil then
local path = JNI:callObjectMethod(
uri,
"getPath",
"()Ljava/lang/String;"
)
return JNI:to_string(path)
end
end)
A.LOGI("intent file path " .. (file or ""))
-- run koreader patch before koreader startup
pcall(function() dofile("/sdcard/koreader/patch.lua") end)
-- set proper permission for sdcv
A.execute("chmod", "755", "./sdcv")
-- set TESSDATA_PREFIX env var
ffi.C.putenv("TESSDATA_PREFIX=/sdcard/koreader/data")
-- create fake command-line arguments
arg = {"-d", file or "/sdcard"}
dofile(A.dir.."/reader.lua")