#274 bugfixes and optimizations

This commit is contained in:
Mikayla Fischler 2023-07-16 21:07:37 -04:00
parent 4d9783beca
commit b54f15bad6
2 changed files with 15 additions and 11 deletions

View File

@ -20,7 +20,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local function println(message) print(tostring(message)) end local function println(message) print(tostring(message)) end
local function print(message) term.write(tostring(message)) end local function print(message) term.write(tostring(message)) end
local CCMSI_VERSION = "v1.7a" local CCMSI_VERSION = "v1.7b"
local install_dir = "/.install-cache" local install_dir = "/.install-cache"
local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/" local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/"
@ -57,7 +57,7 @@ end
-- wait for any key to be pressed -- wait for any key to be pressed
---@diagnostic disable-next-line: undefined-field ---@diagnostic disable-next-line: undefined-field
local function any_key() os.pullEvent("key") end local function any_key() os.pullEvent("key_up") end
-- print out a white + blue text message -- print out a white + blue text message
local function pkg_message(message, package) white();print(message .. " ");blue();println(package);white() end local function pkg_message(message, package) white();print(message .. " ");blue();println(package);white() end
@ -157,15 +157,13 @@ local function _clean_dir(dir, tree)
if tree == nil then tree = {} end if tree == nil then tree = {} end
local ls = fs.list(dir) local ls = fs.list(dir)
for _, val in pairs(ls) do for _, val in pairs(ls) do
local path = dir.."/"..val local path = dir .. "/" .. val
if fs.isDir(path) then if fs.isDir(path) then
_clean_dir(path, tree[val]) _clean_dir(path, tree[val])
if #fs.list(path) == 0 then if #fs.list(path) == 0 then fs.delete(path);println("deleted dir " .. path) end
fs.delete(path);lgray();println("deleted dir " .. path);white()
end
elseif not _in_array(val, tree) then elseif not _in_array(val, tree) then
fs.delete(val) fs.delete(path)
lgray();println("deleted " .. path);white() println("deleted " .. path)
end end
end end
end end
@ -174,19 +172,25 @@ end
local function clean(manifest) local function clean(manifest)
local root_ext = false local root_ext = false
local tree = gen_tree(manifest) local tree = gen_tree(manifest)
table.insert(tree, "install_manifest.json") table.insert(tree, "install_manifest.json")
table.insert(tree, "ccmsi.lua") table.insert(tree, "ccmsi.lua")
table.insert(tree, "log.txt") table.insert(tree, "log.txt")
lgray()
local ls = fs.list("/") local ls = fs.list("/")
for _, val in pairs(ls) do for _, val in pairs(ls) do
if fs.isDir(val) then if fs.isDir(val) then
if tree[val] ~= nil then _clean_dir("/" .. val, tree[val]) end if tree[val] ~= nil then _clean_dir("/" .. val, tree[val]) end
if #fs.list(val) == 0 then fs.delete(val) end if #fs.list(val) == 0 then fs.delete(val);println("deleted dir " .. val) end
elseif not _in_array(val, tree) then elseif not _in_array(val, tree) then
root_ext = true root_ext = true
yellow();println(val .. " not used");white() yellow();println(val .. " not used")
end end
end end
white()
if root_ext then println("Files in root directory won't be automatically deleted.") end if root_ext then println("Files in root directory won't be automatically deleted.") end
end end

File diff suppressed because one or more lines are too long