Merge pull request #310 from tigran123/master

Fix a crash in getDiskSizeInfo() (in emulator) and use util.df function.
This commit is contained in:
{Qingping,Dave} Hou
2012-09-24 13:54:32 -07:00
4 changed files with 19 additions and 22 deletions

View File

@@ -35,19 +35,16 @@ function CREReader:init()
self.default_font = default_font
end
end
-- inspect the zipfile content
function CREReader:ZipContentExt(fname)
local i, s = 1
local tmp = assert(io.popen('unzip -l \"'..fname..'\"', "r"))
while tmp do
s = tmp:read("*line")
if i > 3 then tmp:close(); break; end
i = i + 1
end
local tmp = assert(io.popen('unzip -l \"'..fname..'\" | head -4 | tail -1', "r"))
s = tmp:read("*line")
tmp:close()
return s and string.lower(string.match(s, ".+%.([^.]+)"))
end
-- open a CREngine supported file and its settings store
function CREReader:open(filename)
local ok

View File

@@ -46,15 +46,8 @@ function getUnpackedZipSize(zipfile)
end
function getDiskSizeInfo()
local s = {}
local tmp = assert(io.popen('df /mnt/us/ | tail -1', "r"))
local output = assert(tmp:read("*line"))
for w in string.gmatch(output, "%d+") do
s[#s+1] = tonumber(w)*1024 -- to return in bytes
end
tmp:close()
if #s < 3 then return nil end
return { total = s[1], used = s[2], free = s[3] }
local t, f = util.df(".")
return { total = t, free = f }
end
function FileInfo:formatDiskSizeInfo()
@@ -69,9 +62,7 @@ function FileInfo:getFolderContent()
InfoMessage:show("Scanning folder...", 1)
local tmp = assert(io.popen('du -a \"'..self.pathfile..'\"', "r"))
local dirs, files, books, size, name, output, ftype, j = -1, 0, 0, 0
while true do
output = tmp:read("*line")
if not output then break end
for output in tmp:lines() do
j = output:find("/")
name = output:sub(j, -1)
size = tonumber(output:sub(1, j-1)) -- in kB

View File

@@ -1642,14 +1642,22 @@ function UniReader:fillToc()
end
elseif (v.depth == prev_depth) then --> k and prev are siblings
parent[k] = parent[prev]
table.insert(self.toc_children[parent[k]], k)
if not self.toc_children[parent[k]] then
table.insert(self.toc_children[0],k)
else
table.insert(self.toc_children[parent[k]], k)
end
else --> k and prev must have a common (possibly virtual) ancestor
local par = parent[prev]
while (self.toc[par].depth > v.depth) do
par = parent[par]
end
parent[k] = parent[par]
table.insert(self.toc_children[parent[k]], k)
if not self.toc_children[parent[k]] then
table.insert(self.toc_children[0],k)
else
table.insert(self.toc_children[parent[k]], k)
end
end
prev = k
prev_depth = self.toc[prev].depth

3
util.c
View File

@@ -46,8 +46,9 @@ static int util_df(lua_State *L) {
char *path = luaL_checkstring(L, 1);
struct statvfs vfs;
statvfs(path, &vfs);
lua_pushnumber(L, (double)vfs.f_blocks * (double)vfs.f_bsize);
lua_pushnumber(L, (double)vfs.f_bfree * (double)vfs.f_bsize);
return 1;
return 2;
}
/* Turn UTF-8 char code to Unicode */