From 90f1537fa4c612a11e5d0777acb5b62ec44ffb1c Mon Sep 17 00:00:00 2001 From: Jane Roxanne Date: Fri, 6 Mar 2020 09:16:42 -0500 Subject: [PATCH] Stuff^2 --- src/zy-neo/builtins/init_managed/init.lua | 27 +++++++++++++++++----- src/zy-neo/builtins/util_romfs.lua | 13 ++++++++--- src/zy-neo/zinit.lua | 6 ++--- utils/romfs.lua | 0 utils/ser.lua | 28 +++++++++++++++++------ 5 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 utils/romfs.lua diff --git a/src/zy-neo/builtins/init_managed/init.lua b/src/zy-neo/builtins/init_managed/init.lua index ea1ffca..94f1e62 100644 --- a/src/zy-neo/builtins/init_managed/init.lua +++ b/src/zy-neo/builtins/init_managed/init.lua @@ -1,14 +1,14 @@ local readfile=function(f,h) local b="" - local d,r=component.invoke(f,"read",h,math.huge) + local d,r=f.read(h,math.huge) if not d and r then error(r)end b=d while d do - local d,r=component.invoke(f,"read",h,math.huge) + local d,r=f.read(h,math.huge) b=b..(d or "") if(not d)then break end end - component.invoke(f,"close",h) + f.close(h) return b end @@ -17,15 +17,30 @@ local bfs = {} local cfg = component.proxy(component.list("eeprom")()).getData() local baddr = cfg:sub(1, 36) +local bootfs = component.proxy(baddr) + +local romfs_file = component.invoke(baddr, "open", ".zy2/bootimage.romfs") + +local romfs_dev = romfs.read(function(a) + return bootfs.read(romfs_file, a) +end, function(a) + return bootfs.seek(romfs_file, "cur", a) +end, function() + return bootfs.close(romfs_file) +end) function bfs.getfile(path) - local h = assert(component.invoke(baddr, "open", path, "r")) - return readfile(baddr, h) + return romfs_dev:fetch(path) end function bfs.exists(path) - return component.invoke(baddr, "exists", path) + return romfs_dev:exists(path) end +function bfs.getcfg() + local h = assert(bootfs.open(".zy2/cfg.lua", "r")) + readfile(bootfs, h) + return +end bfs.addr = baddr \ No newline at end of file diff --git a/src/zy-neo/builtins/util_romfs.lua b/src/zy-neo/builtins/util_romfs.lua index cb223b4..913b9d0 100644 --- a/src/zy-neo/builtins/util_romfs.lua +++ b/src/zy-neo/builtins/util_romfs.lua @@ -30,6 +30,15 @@ function arc:fetch(path) return nil, "file not found" end +function arc:exists(path) + for i=1, #self.tbl do + if (self.tbl[i].name == path) then + return true + end + end + return false +end + function arc:close() self.close() self.tbl = nil @@ -47,6 +56,4 @@ function arc:list_dir(path) end end return ent -end - -return romfs \ No newline at end of file +end \ No newline at end of file diff --git a/src/zy-neo/zinit.lua b/src/zy-neo/zinit.lua index 4bf868f..3b06992 100644 --- a/src/zy-neo/zinit.lua +++ b/src/zy-neo/zinit.lua @@ -32,6 +32,8 @@ end local builtins = {} --#include "src/zy-neo/utils.lua" +--#include "src/zy-neo/builtins/util_romfs.lua" + sys.add_lib("zorya", (function() local mod_search = {} @@ -48,9 +50,7 @@ sys.add_lib("zorya", (function() local loaded_mods = {} - loaded_mods.util_romfs = (function() ---#include "src/zy-neo/builtins/util_romfs.lua" - end)() + loaded_mods.util_romfs = romfs function zy.loadmod(mod) if (loaded_mods[mod]) then return loaded_mods[mod] end diff --git a/utils/romfs.lua b/utils/romfs.lua deleted file mode 100644 index e69de29..0000000 diff --git a/utils/ser.lua b/utils/ser.lua index 3d541cc..a4f5cad 100644 --- a/utils/ser.lua +++ b/utils/ser.lua @@ -90,12 +90,6 @@ function setBar(pos) computer.pullSignal(0) end -function writeFile(fs, path, data) - local hand = fs.open(path, "w") - fs.write(hand, data) - fs.close(hand) -end - function mkdir(fs, path) fs.makeDirectory(path) end @@ -108,6 +102,24 @@ fs.makeDirectory(".zy2") fs.makeDirectory(".zy2/mods") fs.makeDirectory(".zy2/lib") +local romfs = fs.open(".zy2/image.romfs", "w") +fs.write(romfs, "romfs\1\0") + +function writeFile(path, data) + --local hand = fs.open(path, "w") + --fs.write(hand, data) + --fs.close(hand) + fs.write(romfs, string.char(#path)..path) + local ext = path:sub(#path-2) + if (ext == "lua" or ext == "z2l" or ext == "z2y") then + fs.write(romfs, "x") + else + fs.write(romfs, "-") + end + fs.write(romfs, string.pack("