From c9c89ef56ddbd4c26bdd939842e6fcc03fd18c16 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 18 Sep 2012 10:07:30 +0100 Subject: [PATCH 1/4] Use the proper way to detect emulation. --- screen.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screen.lua b/screen.lua index 621d84926..f79bc2708 100644 --- a/screen.lua +++ b/screen.lua @@ -67,7 +67,7 @@ function Screen:screenRotate(orien) end function Screen:updateRotationMode() - if KEY_FW_DOWN == 116 then -- in EMU mode always set to 0 + if util.isEmulated() == 1 then -- in EMU mode always set to 0 self.cur_rotation_mode = 0 else orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r")) From c43fb549d30ae5b8823c520a89813328f381c0d4 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 18 Sep 2012 23:36:01 +0100 Subject: [PATCH 2/4] Avoid writing to files when obtaining the battery level --- use pipes instead. --- filechooser.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index dda40167d..9ae9aa97d 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -55,15 +55,12 @@ function getProperTitleLength(txt,font_face,max_width) end function BatteryLevel() - local fn, battery = "/tmp/kindle-battery-info", "?" -- NuPogodi, 18.05.12: This command seems to work even without Amazon Kindle framework - os.execute("gasgauge-info -s 2> /dev/null > "..fn) - if io.open(fn,"r") then - for lines in io.lines(fn) do battery = " " .. lines end - else - battery = "" - end - return battery + local cmd="gasgauge-info -s 2> /dev/null" + local p = assert(io.popen(cmd, "r")) + local battery = assert(p:read("*a")) + p:close() + return string.gsub(battery, "[\n\r]+", "") end function DrawTitle(text,lmargin,y,height,color,font_face) From 456136ef710be36c96d21abb14c8b120702a3035 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 18 Sep 2012 23:40:18 +0100 Subject: [PATCH 3/4] Fix the calculation of the total unpacked size of the content of a zip file when it contains multiple entries. Also, don't write to temporary files in the physical filesystem --- use pipes instead. --- fileinfo.lua | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/fileinfo.lua b/fileinfo.lua index c04dfa825..c75e26bcd 100644 --- a/fileinfo.lua +++ b/fileinfo.lua @@ -30,6 +30,15 @@ function FileInfo:FileSize(size) end end +function getUnpackedZipSize(zipfile) + local cmd='unzip -l '..zipfile..' | tail -1 | sed -e "s/^ *\\([0-9][0-9]*\\) *.*/\\1/"' + local p = assert(io.popen(cmd, "r")) + local res = assert(p:read("*a")) + p:close() + res = string.gsub(res, "[\n\r]+", "") + return tonumber(res) +end + function FileInfo:init(path, fname) self.pathfile = path.."/"..fname self.result = {} @@ -45,25 +54,16 @@ function FileInfo:init(path, fname) info_entry = {dir = "Size", name = FileInfo:FileSize(lfs.attributes(self.pathfile, "size"))} table.insert(self.result, info_entry) - -- size & filename of unzipped entry for zips - if string.lower(string.match(fname, ".+%.([^.]+)")) == "zip" then - local outfile = "./data/zip_content" - local l, s = 1 - os.execute("unzip -l \""..self.pathfile.."\" > "..outfile) - if io.open(outfile, "r") then - for lines in io.lines(outfile) do - if l == 4 then s = lines break else l = l + 1 end - end - if s then - info_entry = { dir = "Unpacked", name = FileInfo:FileSize(tonumber(string.sub(s,1,11))) } - table.insert(self.result, info_entry) - end - --[[ TODO: When the fileentry inside zips is encoded as ANSI (codes 128-255) - any attempt to print such fileentry causes crash by drawing!!! When fileentries - are encoded as UTF8, everything seems fine - info_entry = { dir = "Content", name = string.sub(s,29,-1) } - table.insert(self.result, info_entry) ]] - end + -- total size of all unzipped entries for zips + local match = string.match(fname, ".+%.([^.]+)") + if match and string.lower(match) == "zip" then + info_entry = {dir = "Unpacked", name = FileInfo:FileSize(getUnpackedZipSize(self.pathfile))} + table.insert(self.result, info_entry) + --[[ TODO: When the fileentry inside zips is encoded as ANSI (codes 128-255) + any attempt to print such fileentry causes crash by drawing!!! When fileentries + are encoded as UTF8, everything seems fine + info_entry = { dir = "Content", name = string.sub(s,29,-1) } + table.insert(self.result, info_entry) ]] end info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile, "change")} From 4b9cf4eaf52fbd7ffd5c3bf16ea38aaaed80747b Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 18 Sep 2012 23:52:11 +0100 Subject: [PATCH 4/4] Use os.remove() instead of os.execute("rm...") because it is less expensive as it uses remove(3) C library function rather than fork/exec-ing a new process. --- filehistory.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filehistory.lua b/filehistory.lua index 6fc5bd717..e5cffdcc8 100644 --- a/filehistory.lua +++ b/filehistory.lua @@ -217,7 +217,7 @@ function FileHistory:addAllCommands() function(self) file_entry = self.result[self.perpage*(self.page-1)+self.current] local file_to_del = file_entry.dir .. "/" .. file_entry.name - os.execute("rm \""..DocToHistory(file_to_del).."\"") + os.remove(DocToHistory(file_to_del)) -- to avoid showing just deleted file self:init() self:setSearchResult(self.keywords)