mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #250 from NuPogodi/master
fix: to prevent crashes at opening wrong zips or zips with not crengine-related documents
This commit is contained in:
@@ -34,26 +34,37 @@ function CREReader:init()
|
||||
end
|
||||
-- inspect the zipfile content
|
||||
function CREReader:ZipContentExt(fname)
|
||||
local outfile = "./data/zip_content"
|
||||
local s = ""
|
||||
os.execute("unzip ".."-l \""..fname.."\" > "..outfile)
|
||||
local outfile, s = "./data/zip_content"
|
||||
os.execute("unzip -l \""..fname.."\" > "..outfile)
|
||||
local i = 1
|
||||
if io.open(outfile,"r") then
|
||||
for lines in io.lines(outfile) do
|
||||
if i == 4 then s = lines break else i = i + 1 end
|
||||
end
|
||||
end
|
||||
-- return the extention
|
||||
return string.lower(string.match(s, ".+%.([^.]+)"))
|
||||
if s then -- return the extention
|
||||
return string.lower(string.match(s, ".+%.([^.]+)") or "")
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- open a CREngine supported file and its settings store
|
||||
function CREReader:open(filename)
|
||||
local ok
|
||||
local file_type = string.lower(string.match(filename, ".+%.([^.]+)"))
|
||||
local file_type = string.lower(string.match(filename, ".+%.([^.]+)") or "")
|
||||
-- check zips for potential problems - wrong zip & wrong content
|
||||
if file_type == "zip" then
|
||||
file_type = self:ZipContentExt(filename)
|
||||
end
|
||||
if not file_type then
|
||||
return false, "Error unzipping file. "
|
||||
end
|
||||
-- if the zip entry is not cre-document
|
||||
if ext:getReader(file_type) ~= CREReader then
|
||||
return false, "Zip contains improper content. "
|
||||
end
|
||||
-- these two format use the same css file
|
||||
if file_type == "html" then
|
||||
file_type = "htm"
|
||||
@@ -63,10 +74,9 @@ function CREReader:open(filename)
|
||||
file_type = "cr3"
|
||||
end
|
||||
local style_sheet = "./data/"..file_type..".css"
|
||||
ok, self.doc = pcall(cre.openDocument, filename, style_sheet,
|
||||
G_width, G_height)
|
||||
ok, self.doc = pcall(cre.openDocument, filename, style_sheet, G_width, G_height)
|
||||
if not ok then
|
||||
return false, self.doc -- will contain error message
|
||||
return false, "Error opening cre-document. " -- self.doc, will contain error message
|
||||
end
|
||||
self.doc:setDefaultInterlineSpace(self.line_space_percent)
|
||||
return true
|
||||
|
||||
@@ -53,7 +53,7 @@ function openFile(filename)
|
||||
G_reader_settings:saveSetting("lastfile", filename)
|
||||
return reader:inputLoop()
|
||||
else
|
||||
InfoMessage:show("Error opening document.", 0)
|
||||
InfoMessage:show(err or "Error opening document.", 0)
|
||||
util.sleep(2)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2007,18 +2007,18 @@ function UniReader:addAllCommands()
|
||||
(keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK)
|
||||
and unireader:prevView() or unireader:nextView())
|
||||
end)
|
||||
self.commands:addGroup(MOD_SHIFT.."< >",{
|
||||
Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_SHIFT),
|
||||
Keydef:new(KEY_LPGBCK,MOD_SHIFT),Keydef:new(KEY_LPGFWD,MOD_SHIFT)},
|
||||
self.commands:addGroup(MOD_ALT.."< >",{
|
||||
Keydef:new(KEY_PGBCK,MOD_ALT),Keydef:new(KEY_PGFWD,MOD_ALT),
|
||||
Keydef:new(KEY_LPGBCK,MOD_ALT),Keydef:new(KEY_LPGFWD,MOD_ALT)},
|
||||
"zoom out/in ".. self.step_manual_zoom .."% ",
|
||||
function(unireader,keydef)
|
||||
local is_zoom_out = (keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK)
|
||||
unireader:setGlobalZoom(unireader.globalzoom_orig * (1 + (is_zoom_out and -1 or 1)*unireader.step_manual_zoom/100))
|
||||
end)
|
||||
-- NuPogodi, 03.09.12: make zoom step user-configurable
|
||||
self.commands:addGroup(MOD_ALT.."< >",{
|
||||
Keydef:new(KEY_PGBCK,MOD_ALT),Keydef:new(KEY_PGFWD,MOD_ALT),
|
||||
Keydef:new(KEY_LPGBCK,MOD_ALT),Keydef:new(KEY_LPGFWD,MOD_ALT)},
|
||||
self.commands:addGroup(MOD_SHIFT.."< >",{
|
||||
Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_SHIFT),
|
||||
Keydef:new(KEY_LPGBCK,MOD_SHIFT),Keydef:new(KEY_LPGFWD,MOD_SHIFT)},
|
||||
"decrease/increase zoom step",
|
||||
function(unireader,keydef)
|
||||
if keydef.keycode == KEY_PGFWD or keydef.keycode == KEY_LPGFWD then
|
||||
@@ -2593,6 +2593,10 @@ function UniReader:addAllCommands()
|
||||
local minstep = 1
|
||||
if keydef.keycode == KEY_FW_RIGHT then
|
||||
unireader.shift_x = unireader.shift_x * 2
|
||||
if unireader.shift_x >= G_width then
|
||||
unireader.shift_x = G_width
|
||||
showInfoMsgWithDelay("Maximum X-panning step is "..G_width..". ", 2000, 1)
|
||||
end
|
||||
self.settings:saveSetting("shift_x", self.shift_x)
|
||||
--showInfoMsgWithDelay("New X-panning step is "..unireader.shift_x..". ", 2000, 1)
|
||||
else
|
||||
@@ -2612,6 +2616,10 @@ function UniReader:addAllCommands()
|
||||
local minstep = 1
|
||||
if keydef.keycode == KEY_FW_UP then
|
||||
unireader.shift_y = unireader.shift_y * 2
|
||||
if unireader.shift_y >= G_height then
|
||||
unireader.shift_y = G_height
|
||||
showInfoMsgWithDelay("Maximum Y-panning step is "..G_height..". ", 2000, 1)
|
||||
end
|
||||
self.settings:saveSetting("shift_y", self.shift_y)
|
||||
--showInfoMsgWithDelay("New Y-panning step is "..unireader.shift_y..". ", 2000, 1)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user