diff --git a/filechooser.lua b/filechooser.lua index bb7f26d4f..ce6332a7d 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -532,7 +532,7 @@ function FileChooser:addAllCommands() self.pagedirty = true end ) - self.commands:add(KEY_HOME, nil, "Back", + self.commands:add(KEY_HOME, nil, "Home", "exit", function(self) return "break" diff --git a/fileinfo.lua b/fileinfo.lua index c75e26bcd..aadb2c20e 100644 --- a/fileinfo.lua +++ b/fileinfo.lua @@ -23,10 +23,15 @@ function FileInfo:FileCreated(fname, attr) return os.date("%d %b %Y, %H:%M:%S", lfs.attributes(fname,attr)) end -function FileInfo:FileSize(size) - if size < 1024 then return size.." Bytes" - elseif size < 2^20 then return string.format("%.2f", size/2^10).."KB ("..size.." Bytes)" - else return string.format("%.2f", size/2^20).."MB ("..size.." Bytes)" +function FileInfo:FormatSize(size) + if size < 1024 then + return size.." Bytes" + elseif size < 2^20 then + return string.format("%.2f", size/2^10).."KB ("..size.." Bytes)" + elseif size < 2^30 then + return string.format("%.2f", size/2^20).."MB ("..size.." Bytes)" + else + return string.format("%.2f", size/2^30).."GB ("..size.." Bytes)" end end @@ -52,12 +57,12 @@ function FileInfo:init(path, fname) info_entry = {dir = "Path", name = path} table.insert(self.result, info_entry) - info_entry = {dir = "Size", name = FileInfo:FileSize(lfs.attributes(self.pathfile, "size"))} + info_entry = {dir = "Size", name = FileInfo:FormatSize(lfs.attributes(self.pathfile, "size"))} table.insert(self.result, info_entry) -- 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))} + info_entry = {dir = "Unpacked", name = FileInfo:FormatSize(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 @@ -66,6 +71,8 @@ function FileInfo:init(path, fname) table.insert(self.result, info_entry) ]] end + info_entry = {dir = "Free space", name = FileInfo:FormatSize(util.df("."))} + table.insert(self.result, info_entry) info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile, "change")} table.insert(self.result, info_entry) info_entry = {dir = "Modified", name = FileInfo:FileCreated(self.pathfile, "modification")} diff --git a/util.c b/util.c index 061847723..6a61d3e22 100644 --- a/util.c +++ b/util.c @@ -17,6 +17,7 @@ */ #include +#include #include #include "util.h" @@ -41,10 +42,18 @@ static int util_usleep(lua_State *L) { return 0; } +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_bfree * (double)vfs.f_bsize); + return 1; +} + /* Turn UTF-8 char code to Unicode */ static int utf8charcode(lua_State *L) { size_t len; - const char* utf8char = luaL_checklstring(L, 1, &len); + const char *utf8char = luaL_checklstring(L, 1, &len); int c; if(len == 1) { c = utf8char[0] & 0x7F; /* should not be needed */ @@ -75,6 +84,7 @@ static const struct luaL_Reg util_func[] = { {"usleep", util_usleep}, {"utf8charcode", utf8charcode}, {"isEmulated", isEmulated}, + {"df", util_df}, {NULL, NULL} };