mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
mod: call different reader in reader.lua
call PDFReader or DJVUReader according to filetype
This commit is contained in:
56
reader.lua
56
reader.lua
@@ -31,6 +31,22 @@ longopts = {
|
||||
device = "d",
|
||||
help = "h"
|
||||
}
|
||||
|
||||
function openFile(filename)
|
||||
local file_type = string.lower(string.match(filename, ".+%.(.+)"))
|
||||
if file_type == "djvu" then
|
||||
if DJVUReader:open(filename) then
|
||||
DJVUReader:goto(tonumber(DJVUReader.settings:readsetting("last_page")) or 1)
|
||||
DJVUReader:inputloop()
|
||||
end
|
||||
elseif file_type == "pdf" then
|
||||
if PDFReader:open(filename,"") then -- TODO: query for password
|
||||
PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
||||
PDFReader:inputloop()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
optarg, optind = alt_getopt.get_opts(ARGV, "p:G:hg:d:", longopts)
|
||||
if optarg["h"] or ARGV[optind] == nil then
|
||||
print("usage: ./reader.lua [OPTION] ... DOCUMENT.PDF")
|
||||
@@ -93,50 +109,26 @@ if r_cfont ~=nil then
|
||||
FontChooser.cfont = r_cfont
|
||||
end
|
||||
|
||||
-- display directory or open file
|
||||
if lfs.attributes(ARGV[optind], "mode") == "directory" then
|
||||
local running = true
|
||||
FileChooser:setPath(ARGV[optind])
|
||||
while running do
|
||||
local pdffile = FileChooser:choose(0,height)
|
||||
if pdffile ~= nil then
|
||||
if DJVUReader:open(pdffile,"") then
|
||||
DJVUReader:goto(1)
|
||||
DJVUReader:inputloop()
|
||||
end
|
||||
local file = FileChooser:choose(0,height)
|
||||
if file ~= nil then
|
||||
openFile(file)
|
||||
else
|
||||
running = false
|
||||
end
|
||||
end
|
||||
else
|
||||
DJVUReader:open(ARGV[optind], optarg["p"])
|
||||
DJVUReader:goto(tonumber(optarg["g"]) or tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
||||
DJVUReader:inputloop()
|
||||
openFile(ARGV[optind], optarg["p"])
|
||||
end
|
||||
|
||||
|
||||
--[[if lfs.attributes(ARGV[optind], "mode") == "directory" then]]
|
||||
--local running = true
|
||||
--FileChooser:setPath(ARGV[optind])
|
||||
--while running do
|
||||
--local pdffile = FileChooser:choose(0,height)
|
||||
--if pdffile ~= nil then
|
||||
--if PDFReader:open(pdffile,"") then -- TODO: query for password
|
||||
--PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
||||
--PDFReader:inputloop()
|
||||
--end
|
||||
--else
|
||||
--running = false
|
||||
--end
|
||||
--end
|
||||
--else
|
||||
----PDFReader:open(ARGV[optind], optarg["p"])
|
||||
----PDFReader:goto(tonumber(optarg["g"]) or tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
||||
----PDFReader:inputloop()
|
||||
--end
|
||||
|
||||
---- save reader settings
|
||||
--reader_settings:savesetting("cfont", FontChooser.cfont)
|
||||
--reader_settings:close()
|
||||
-- save reader settings
|
||||
reader_settings:savesetting("cfont", FontChooser.cfont)
|
||||
reader_settings:close()
|
||||
|
||||
input.closeAll()
|
||||
--os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ')
|
||||
|
||||
Reference in New Issue
Block a user