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 local FList = {} local root = cdutil:findpath(arg_dir) List.RemoveItem = nil 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) .. " " FList[i] = { full = entry.Parent .. entry.Name, type = entry.TypeFile } end List.FList = FList end, fillListComplete = function (self, List, ISOElements) local FList = {} List.RemoveItem = nil 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) FList[i] = { full = entry.Parent .. entry.Name, type = entry.TypeFile } end List.FList = FList end, getISOElements = function (self) local ISOElements = {} local cdutil = self.cdutil local function list_tree(arg_root) local root = cdutil:findpath(arg_root) local tree = {} for name, dir in root:iterate(cdutil) do if name ~= "." and name ~= ".." then local elem = { Name = name, Size = dir.Size, Sector = dir.Sector, 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, } if dir:isdir() then elem.TypeFile = "File Folder" local subtree = list_tree(arg_root .. name .. "/") subtree.branchname = name table.insert(tree, subtree) else elem.TypeFile = "File" end table.insert(ISOElements, elem) end end return tree end tree = list_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 self:set_houtput(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) tab.ninputs = 1 tab.noutputs = 1 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) 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" function controlList:dblclick_cb(pos, text) --[[ if currentDir[pos].TypeFile == "File Folder" then obj:fillList(self.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 obj:fillList(controlList, dir) return iup.DEFAULT end local listAction = function (self, text, pos, state) if state ~= 1 then return iup.DEFAULT end local file = self.FList[pos] if file.type == "File" then local cdutil = obj.cdutil local dir = cdutil:findpath(file.full) obj:set_houtput(cdutil:cdfile(dir)) else obj:set_houtput(nil) end return iup.DEFAULT end controlList.action = listAction controlListComplete.action = listAction 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, }, }, }, } 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")