Skip to content
Permalink
Browse files

Allow selecting iso from install dir browser

Also document InstallDirectoryBrowser
  • Loading branch information...
TheCycoONE committed May 27, 2019
1 parent 7908c30 commit 8a050f93f2253ea8dd928d7d00cad60f9d468ace
Showing with 37 additions and 0 deletions.
  1. +37 −0 CorsixTH/Lua/dialogs/resizables/directory_browser.lua
@@ -20,6 +20,7 @@ SOFTWARE. --]]

local lfs = require("lfs")
local TH = require("TH")
local iso_fs = TH.iso_fs()
local lfsext = TH.lfsExt()

--! A tree node representing a directory in the physical file-system.
@@ -70,10 +71,38 @@ function InstallDirTreeNode:createNewNode(path)
return InstallDirTreeNode(path)
end

--! Test if file name has an .iso extension
local function isIso(name)
if name == nil then
return false
end

local ext = 'iso'
return string.sub(name:lower(), -string.len(ext)) == ext
end

--! Test whether this file node is a directory or iso file.
--
--!return (bool) true if directory or iso, false otherwise
function InstallDirTreeNode:isValidFile(name)
-- Check parent criteria and that it's a directory.
if FileTreeNode.isValidFile(self, name) then
return DirTreeNode.isValidFile(self, name) or isIso(name)
end
return false
end


function InstallDirTreeNode:select()
-- Do nothing as an override. getHighlightColour solves this instead.
end

--! Check whether this node is a valid install selection.
--
-- Sets self.is_valid_directory to true if the selection is valid.
--
--!return (colour) A highlight colour if the node is a valid selection, or nil
-- otherwise.
function InstallDirTreeNode:getHighlightColour(canvas)
local highlight_colour = self.highlight_colour
if highlight_colour == nil then
@@ -97,6 +126,14 @@ function InstallDirTreeNode:getHighlightColour(canvas)
highlight_colour = canvas:mapRGB(0, 255, 0)
self.is_valid_directory = true
end
elseif isIso(self.path) then
local file = io.open(self.path, "rb")
if not file then return nil end
if iso_fs:setRoot(file) then
highlight_colour = canvas:mapRGB(0, 255, 0)
self.is_valid_directory = true
end
io.close(file)
end
self.highlight_colour = highlight_colour
end

0 comments on commit 8a050f9

Please sign in to comment.
You can’t perform that action at this time.