2019-08-29 19:59:39 +00:00
|
|
|
local android = require("android")
|
|
|
|
android.dl.library_path = android.dl.library_path .. ":" .. android.dir .. "/libs"
|
2014-06-01 15:53:09 +00:00
|
|
|
|
2020-06-19 19:23:47 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2015-06-15 08:46:43 +00:00
|
|
|
local ffi = require("ffi")
|
2019-03-29 19:12:09 +00:00
|
|
|
local dummy = require("ffi/posix_h")
|
2018-06-02 16:10:55 +00:00
|
|
|
local C = ffi.C
|
2015-06-15 08:46:43 +00:00
|
|
|
|
2014-10-28 18:27:29 +00:00
|
|
|
-- check uri of the intent that starts this application
|
2019-08-29 19:59:39 +00:00
|
|
|
local file = android.getIntent()
|
2018-12-29 19:48:19 +00:00
|
|
|
|
|
|
|
if file ~= nil then
|
2019-08-29 19:59:39 +00:00
|
|
|
android.LOGI("intent file path " .. file)
|
2018-12-29 19:48:19 +00:00
|
|
|
end
|
2014-10-28 18:27:29 +00:00
|
|
|
|
2019-10-13 23:24:46 +00:00
|
|
|
-- path to primary external storage partition
|
|
|
|
local path = android.getExternalStoragePath()
|
|
|
|
|
2020-06-20 16:06:24 +00:00
|
|
|
-- run user shell scripts or recursive migration of user data
|
|
|
|
local function runUserScripts(dir, migration, parent)
|
2020-06-19 19:23:47 +00:00
|
|
|
for entry in lfs.dir(dir) do
|
|
|
|
if entry ~= "." and entry ~= ".." then
|
|
|
|
local fullpath = dir .. "/" .. entry
|
|
|
|
local mode = lfs.attributes(fullpath).mode
|
2020-06-20 16:06:24 +00:00
|
|
|
if mode == "file" and migration then
|
|
|
|
if entry ~= "migrate" and not fullpath:match(".sh$") then
|
|
|
|
local destdir = parent and android.dir .. "/" .. parent or android.dir
|
|
|
|
-- we cannot create new directories on asset storage.
|
|
|
|
-- trying to do that crashes the VM with error=13, Permission Denied
|
|
|
|
android.execute("cp", fullpath, destdir .."/".. entry)
|
|
|
|
end
|
|
|
|
elseif mode == "file" and fullpath:match(".sh$") then
|
2020-06-19 19:23:47 +00:00
|
|
|
android.execute("sh", fullpath, path .. "/koreader", android.dir)
|
|
|
|
elseif mode == "directory" then
|
2020-06-20 16:06:24 +00:00
|
|
|
runUserScripts(fullpath, migration, parent and parent .. "/" .. entry or entry) -- recurse into next directory
|
2020-06-19 19:23:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-22 22:18:35 +00:00
|
|
|
if android.prop.flavor ~= "fdroid" then
|
|
|
|
-- run scripts once after an update of koreader,
|
|
|
|
-- it can also trigger a recursive migration of user data
|
|
|
|
local run_once_scripts = path .. "/koreader/scripts.afterupdate"
|
|
|
|
if lfs.attributes(run_once_scripts, "mode") == "directory" then
|
|
|
|
local afterupdate_marker = android.dir .. "/afterupdate.marker"
|
|
|
|
if lfs.attributes(afterupdate_marker, "mode") ~= nil then
|
|
|
|
if lfs.attributes(run_once_scripts .. "/migrate", "mode") ~= nil then
|
|
|
|
android.LOGI("after-update: running migration")
|
|
|
|
runUserScripts(run_once_scripts, true)
|
|
|
|
else
|
|
|
|
android.LOGI("after-update: running shell scripts")
|
|
|
|
runUserScripts(run_once_scripts)
|
|
|
|
end
|
|
|
|
android.execute("rm", afterupdate_marker)
|
|
|
|
end
|
2020-06-20 16:06:24 +00:00
|
|
|
end
|
2020-06-22 22:18:35 +00:00
|
|
|
-- scripts executed every start of koreader, no migration here
|
|
|
|
local run_always_scripts = path .. "/koreader/scripts.always"
|
|
|
|
if lfs.attributes(run_always_scripts, "mode") == "directory" then
|
|
|
|
runUserScripts(run_always_scripts)
|
|
|
|
end
|
|
|
|
-- run koreader patch before koreader startup
|
|
|
|
pcall(dofile, path.."/koreader/patch.lua")
|
2020-06-19 19:23:47 +00:00
|
|
|
end
|
|
|
|
|
2019-09-09 15:17:07 +00:00
|
|
|
-- Set proper permission for binaries.
|
|
|
|
--- @todo Take care of this on extraction instead.
|
|
|
|
-- Cf. <https://github.com/koreader/koreader/issues/5347#issuecomment-529476693>.
|
|
|
|
android.execute("chmod", "755", "./sdcv")
|
|
|
|
|
2015-06-15 08:46:43 +00:00
|
|
|
-- set TESSDATA_PREFIX env var
|
2019-10-13 23:24:46 +00:00
|
|
|
C.setenv("TESSDATA_PREFIX", path.."/koreader/data", 1)
|
2015-06-15 08:46:43 +00:00
|
|
|
|
2014-10-16 01:24:59 +00:00
|
|
|
-- create fake command-line arguments
|
2019-08-29 19:59:39 +00:00
|
|
|
-- luacheck: ignore 121
|
|
|
|
if android.isDebuggable() then
|
2021-01-07 19:38:10 +00:00
|
|
|
arg = {"-d", file}
|
2019-04-17 18:04:07 +00:00
|
|
|
else
|
2021-01-07 19:38:10 +00:00
|
|
|
arg = {file}
|
2019-04-17 18:04:07 +00:00
|
|
|
end
|
|
|
|
|
2019-08-29 19:59:39 +00:00
|
|
|
dofile(android.dir.."/reader.lua")
|