fix the first file in a zip is a directory will raise error in zipContentExt

pull/786/head
chrox 10 years ago
parent 536a3dcc03
commit 38c75f8359

@ -27,18 +27,15 @@ local CreDocument = Document:new{
} }
-- NuPogodi, 20.05.12: inspect the zipfile content -- NuPogodi, 20.05.12: inspect the zipfile content
function CreDocument.zipContentExt(self, fname) function CreDocument:zipContentExt(fname)
local outfile = "./data/zip_content" local std_out = io.popen("unzip ".."-qql \""..fname.."\"")
local s = "" if std_out then
os.execute("unzip ".."-l \""..fname.."\" > "..outfile) for line in std_out:lines() do
local i = 1 local size, ext = string.match(line, "%s+(%d+)%s+.+%.([^.]+)")
if io.open(outfile,"r") then -- return the extention
for lines in io.lines(outfile) do if size and ext then return string.lower(ext) end
if i == 4 then s = lines break else i = i + 1 end
end end
end end
-- return the extention
return string.lower(string.match(s, ".+%.([^.]+)"))
end end
function CreDocument:cacheInit() function CreDocument:cacheInit()
@ -82,7 +79,7 @@ function CreDocument:init()
if file_type == "zip" then if file_type == "zip" then
-- NuPogodi, 20.05.12: read the content of zip-file -- NuPogodi, 20.05.12: read the content of zip-file
-- and return extention of the 1st file -- and return extention of the 1st file
file_type = self:zipContentExt(self.file) file_type = self:zipContentExt(self.file) or "unknown"
end end
-- these two format use the same css file -- these two format use the same css file
if file_type == "html" then if file_type == "html" then
@ -100,7 +97,7 @@ function CreDocument:init()
Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE
) )
if not ok then if not ok then
self.error_message = self.doc -- will contain error message self.error_message = self._document -- will contain error message
return return
end end

@ -37,7 +37,7 @@ function DjvuDocument:init()
local ok local ok
ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size) ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size)
if not ok then if not ok then
self.error_message = self.doc -- will contain error message self.error_message = self._document -- will contain error message
return return
end end
self.is_open = true self.is_open = true
@ -46,16 +46,6 @@ function DjvuDocument:init()
self:_readMetadata() self:_readMetadata()
end end
function DjvuDocument:invertTextYAxel(pageno, text_table)
local _, height = self.doc:getOriginalPageSize(pageno)
for _,text in pairs(text_table) do
for _,line in ipairs(text) do
line.y0, line.y1 = (height - line.y1), (height - line.y0)
end
end
return text_table
end
function DjvuDocument:getPageTextBoxes(pageno) function DjvuDocument:getPageTextBoxes(pageno)
return self._document:getPageText(pageno) return self._document:getPageText(pageno)
end end

@ -56,7 +56,7 @@ function PdfDocument:init()
local ok local ok
ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size) ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size)
if not ok then if not ok then
self.error_message = self.doc -- will contain error message self.error_message = self._document -- will contain error message
return return
end end
self.is_open = true self.is_open = true

Loading…
Cancel
Save