diff options
author | Pixel <pixel@nobis-crew.org> | 2010-01-07 11:23:58 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2010-01-07 11:23:58 -0800 |
commit | 90971ef3657ddac80eb02820fcc09f6befe2f74c (patch) | |
tree | f9aae9bdd640c6a8703462476b63e315a10b74b3 /dalos-isoviewer.lua | |
parent | 6c0f0f86aee81a1b2002c86884b6e40403262911 (diff) |
Adding Baha's isoviewer in a basic state.
Diffstat (limited to 'dalos-isoviewer.lua')
-rw-r--r-- | dalos-isoviewer.lua | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/dalos-isoviewer.lua b/dalos-isoviewer.lua new file mode 100644 index 0000000..ebd0433 --- /dev/null +++ b/dalos-isoviewer.lua @@ -0,0 +1,292 @@ +loadmodule "luacd"
+
+local controlTree
+local controlList
+local controlListComplete
+local currentDir
+local ISOElements
+
+dalosp.isoviewer = {
+ completeSpace = function (self, text, size, alignment)
+ local newtext = ""
+
+ if alignment == "right" then
+ for j = size, string.len(text) + 1, -1 do
+ newtext = newtext .. " "
+ end
+ newtext = newtext .. text
+ else
+ newtext = text
+ for j = size, string.len(text) + 1, -1 do
+ newtext = newtext .. " "
+ end
+ end
+
+ return newtext
+ end,
+
+ fillList = function (self, List, arg_dir)
+ local arg_root
+ local index = 1
+ local currentDir = {}
+ local cdutil = self.cdutil
+
+ List[1] = NULL
+
+ local root = cdutil:findpath(arg_dir)
+
+ for name, dir in root:iterate(cdutil) do
+ if name ~= "." and name ~= ".." then
+ local elem
+ if dir:isdir() then
+ elem = {
+ Name = name,
+ Size = dir.Size,
+ Sector = dir.Sector,
+ TypeFile = "File Folder",
+ DateFile = string.format('%02d', dir.Day) .. "/" .. string.format('%02d', dir.Month) .. "/" .. dir.Year .. " " .. string.format('%02d', dir.Hour) .. ":" .. string.format('%02d', dir.Minute) .. ":" .. string.format('%02d', dir.Second),
+ Parent = arg_dir
+ }
+ else
+ elem = {
+ Name = name,
+ Size = dir.Size,
+ Sector = dir.Sector,
+ TypeFile = "File",
+ DateFile = string.format('%02d', dir.Day) .. "/" .. string.format('%02d', dir.Month) .. "/" .. dir.Year .. " " .. string.format('%02d', dir.Hour) .. ":" .. string.format('%02d', dir.Minute) .. ":" .. string.format('%02d', dir.Second),
+ Parent = arg_dir
+ }
+ end
+ table.insert(currentDir, elem)
+ end
+ end
+
+ table.sort(currentDir, function(a, b) if a.TypeFile == b.TypeFile then return a.Name < b.Name else return a.TypeFile > b.TypeFile end end)
+
+ for i, entry in ipairs(currentDir) do
+ List[i] = self:completeSpace(entry.Name, 20) .. " " .. self:completeSpace(entry.Size, 9, "right") .. " " .. self:completeSpace(entry.Sector, 6, "right") .. " " .. self:completeSpace(entry.TypeFile, 15) .. " " .. self:completeSpace(entry.DateFile, 19) .. " "
+ end
+ end,
+
+ fillListComplete = function (self, List, ISOElements)
+ for i, entry in ipairs(ISOElements) do
+ List[i] = self:completeSpace(entry.Name, 20) .. " " .. self:completeSpace(entry.Sector, 6, "right") .. " " .. self:completeSpace(entry.Size, 9, "right") .. " " .. self:completeSpace(math.ceil(entry.Size / 2048), 9, "right") .. " " .. self:completeSpace(entry.TypeFile, 15)
+ end
+ end,
+
+ getISOElements = function (self)
+ local tree = {}
+ local ISOElements = {}
+ local cdutil = self.cdutil
+
+ local function list_tree(arg_root, arg_tree)
+ local root = cdutil:findpath(arg_root)
+
+ for name, dir in root:iterate(cdutil) do
+ if name ~= "." and name ~= ".." then
+ if dir:isdir() then
+ local elem1 = { branchname = name }
+
+ local elem2 = {
+ Name = name,
+ Size = dir.Size,
+ Sector = dir.Sector,
+ TypeFile = "File Folder",
+ DateFile = string.format('%02d', dir.Day) .. "/" .. string.format('%02d', dir.Month) .. "/" .. dir.Year .. " " .. string.format('%02d', dir.Hour) .. ":" .. string.format('%02d', dir.Minute) .. ":" .. string.format('%02d', dir.Second),
+ Parent = arg_root
+ }
+ table.insert(ISOElements, elem2)
+
+ list_tree(arg_root .. name .. "/", elem1)
+ table.insert(arg_tree, elem1)
+ else
+ local elem2 = {
+ Name = name,
+ Size = dir.Size,
+ Sector = dir.Sector,
+ TypeFile = "File",
+ DateFile = string.format('%02d', dir.Day) .. "/" .. string.format('%02d', dir.Month) .. "/" .. dir.Year .. " " .. string.format('%02d', dir.Hour) .. ":" .. string.format('%02d', dir.Minute) .. ":" .. string.format('%02d', dir.Second),
+ Parent = arg_root
+ }
+ table.insert(ISOElements, elem2)
+ end
+ end
+ end
+ end
+
+ list_tree("/", tree)
+
+ table.sort(ISOElements, function(a, b) return a.Sector < b.Sector end)
+
+ return tree, ISOElements
+ end,
+
+ input_change = function (self, ind)
+ local h = self:get_linked_input(ind)
+
+ iup.TreeSetValue(self.controlTree, {})
+ self.controlList.RemoveItem = nil
+ self.controlListComplete.RemoveItem = nil
+
+ if h then
+ local cdutil = cdutils(h)
+ self.cdutil = cdutil
+ local pvd = createpvd(cdutil)
+ local volid = pvd.volid
+ pvd:destroy()
+
+ local treeElements, ISOElements = self:getISOElements()
+ iup.TreeSetValue(self.controlTree, treeElements)
+ self.controlTree.name = volid
+
+ self:fillList(self.controlList, "/")
+ self:fillListComplete(self.controlListComplete, ISOElements)
+ end
+ end,
+
+ create = function (d, tab, settings)
+ local function create_tree(volid)
+ local control_tree = iup.tree {
+ EXPAND = "VERTICAL",
+ RASTERSIZE = "200x300",
+ EXPANDALL = "NO",
+ ADDEXPANDED = "NO",
+ }
+
+ control_tree.name = volid
+
+ return control_tree
+ end
+
+ local function create_list(size)
+ local List = iup.list {
+ VALUE = 4,
+ SIZE = size,
+ EXPAND = "HORIZONTAL",
+ FONT = "Courier New",
+ }
+
+ return List
+ end
+
+ local function createHeader(name, size)
+ return iup.text {
+ VALUE = name,
+ SIZE = size,
+ READONLY = "YES",
+ BGCOLOR = "201 201 201",
+ ALIGNMENT = "ACENTER"
+ }
+ end
+
+ local controlTree, controlList, controlListComplete
+
+ controlTree = create_tree("Root")
+ controlList = create_list("385x270")
+ controlListComplete = create_list("100x270")
+ controlList.MULTIPLE = "YES"
+
+ -- A REVOIR --
+ function controlList:dblclick_cb(pos, text)
+ if currentDir[pos].TypeFile == "File Folder" then
+ fillList(controlList, currentDir[pos].Parent .. currentDir[pos].Name .. "/")
+ end
+ end
+
+ function controlTree:selection_cb(id, status)
+ if status == 0 then return end
+
+ local val = id
+ local parent = {}
+ local dir = ""
+ while tonumber(val) > 0 do
+ table.insert(parent, controlTree["TITLE" .. val] .. "/")
+
+ val = controlTree["parent" .. val]
+ end
+ table.insert(parent, "/")
+
+ for i = table.getn(parent), 1, -1 do
+ dir = dir .. parent[i]
+ end
+
+ fillList(controlList, dir)
+
+ return iup.DEFAULT
+ end
+
+ function controlList:button_cb(but, pressed, x, y, status)
+ if but == iup.BUTTON3 and pressed == 1 then
+ --menuList:popup(iup.MOUSEPOS, iup.MOUSEPOS)
+ end
+
+ return iup.DEFAULT
+ end
+
+ local dlg = iup.dialog {
+ TITLE = "Lua-ISOViewer",
+ MARGIN = "5x5",
+ iup.hbox {
+ controlTree,
+ iup.fill { SIZE = "5x5" },
+ iup.tabs {
+ SIZE = "200x300";
+ iup.vbox {
+ MARGIN = 0,
+ TABTITLE = "Liste";
+ iup.hbox {
+ createHeader("Name" , 123),
+ createHeader("Size" , 67),
+ createHeader("Sector" , 50),
+ createHeader("Type" , 101),
+ createHeader("Date Time", 123),
+ createHeader("XA flags" , 50),
+ },
+ controlList,
+ },
+ iup.vbox {
+ MARGIN = 0,
+ TABTITLE = "Liste complète";
+ iup.hbox {
+ createHeader("Name" , 123),
+ createHeader("Sector" , 50),
+ createHeader("Size" , 67),
+ createHeader("Nb Sector", 67),
+ createHeader("Type" , 101),
+ },
+ controlListComplete,
+ },
+ },
+ },
+ }
+
+ tab.ninputs = 1
+ tab.noutputs = 0
+ tab.otype = dalos.objtype.LUA_VIEWER
+ tab.activate = function (self) self.dlg:show() end
+ tab.configure = dalosp.isoviewer.configure
+ tab.input_change = dalosp.isoviewer.input_change
+ tab.default_name = "Isoviewer"
+ tab.ntype = "Isoviewer"
+ tab.get_settings = dalosp.isoviewer.get_settings
+ local extra = {}
+
+ local obj = dalos.object(d, tab, extra)
+
+ obj.dlg = dlg
+
+ obj.completeSpace = dalosp.isoviewer.completeSpace
+ obj.fillList = dalosp.isoviewer.fillList
+ obj.fillListComplete = dalosp.isoviewer.fillListComplete
+ obj.getISOElements = dalosp.isoviewer.getISOElements
+
+ obj.controlTree = controlTree
+ obj.controlList = controlList
+ obj.controlListComplete = controlListComplete
+
+ return obj
+ end,
+}
+
+dalos.isoviewer = dalosp.isoviewer .create
+dalos:register_obj("Isoviewer", dalos.isoviewer , "Basic Viewers")
|