From 38c75f83599f9e3e85fc4c84babe833455518715 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 11 Aug 2014 20:37:50 +0800 Subject: [PATCH] fix the first file in a zip is a directory will raise error in zipContentExt --- frontend/document/credocument.lua | 21 +++++++++------------ frontend/document/djvudocument.lua | 12 +----------- frontend/document/pdfdocument.lua | 2 +- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index c434a5d96..9020859bb 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -27,18 +27,15 @@ local CreDocument = Document:new{ } -- NuPogodi, 20.05.12: inspect the zipfile content -function CreDocument.zipContentExt(self, fname) - local outfile = "./data/zip_content" - local s = "" - 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 +function CreDocument:zipContentExt(fname) + local std_out = io.popen("unzip ".."-qql \""..fname.."\"") + if std_out then + for line in std_out:lines() do + local size, ext = string.match(line, "%s+(%d+)%s+.+%.([^.]+)") + -- return the extention + if size and ext then return string.lower(ext) end end end - -- return the extention - return string.lower(string.match(s, ".+%.([^.]+)")) end function CreDocument:cacheInit() @@ -82,7 +79,7 @@ function CreDocument:init() if file_type == "zip" then -- NuPogodi, 20.05.12: read the content of zip-file -- and return extention of the 1st file - file_type = self:zipContentExt(self.file) + file_type = self:zipContentExt(self.file) or "unknown" end -- these two format use the same css file if file_type == "html" then @@ -100,7 +97,7 @@ function CreDocument:init() Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE ) if not ok then - self.error_message = self.doc -- will contain error message + self.error_message = self._document -- will contain error message return end diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index f323185b1..f4aec66cb 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -37,7 +37,7 @@ function DjvuDocument:init() local ok ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size) if not ok then - self.error_message = self.doc -- will contain error message + self.error_message = self._document -- will contain error message return end self.is_open = true @@ -46,16 +46,6 @@ function DjvuDocument:init() self:_readMetadata() 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) return self._document:getPageText(pageno) end diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index 7e920e788..761d67f1b 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -56,7 +56,7 @@ function PdfDocument:init() local ok ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size) if not ok then - self.error_message = self.doc -- will contain error message + self.error_message = self._document -- will contain error message return end self.is_open = true