OC-Tsuki/extras/velxboot/init.lua
Sam Roxanne c9c05221d9 wot
2020-06-02 01:23:58 -05:00

67 lines
1.5 KiB
Lua

local eeprom = component.proxy(component.list("eeprom")())
local function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
e=c.byte(a,b)b=b+1
for k=0,7 do h=c.sub
g=h(a,b,b)if e>>k&1<1 and b<#a then
i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1
end
b=b+1
c=c..g
d=h(d..g,-4^6)end
end
return c end
local function boot_velx(addr, path)
local fs = component.proxy(addr)
local h = fs.open(path)
local magic, fver, comp, lver, osid, psize = string.unpack("<c5BBBBxxxxI3xxxxxxxxxx", fs.read(h, 13))
if (magic ~= "\27VelX" or fver ~= 1 or osid ~= 127) then
return
end
local rdat = psize
local dat = ""
local buf = ""
repeat
buf = fs.read(h, rdat)
if (buf) then
dat = dat .. buf
end
rdat = psize - #dat
until rdat == 0 or not buf or buf == ""
if (comp == 1) then
dat = lzss_decompress(dat)
end
local baddr = addr
local bpath = path
function computer.getBootAddress()
return baddr
end
function computer.getBootPath()
return bpath
end
function computer.setBootAddress(a)
eeprom.setData(a..";"..path)
addr = a
end
function computer.setBootPath(p)
eeprom.setData(addr..";"..p)
path = p
end
assert(load(dat, "="..path))()
end
local config = eeprom.getData()
local addr, path = config:match("^(.+);(.+)$")
if not addr then
addr = config
path = "boot.velx"
else
return boot_velx(addr, path)
end
if not component.invoke(addr, "exists", path) then
for d in component.list("filesystem") do
if (component.invoke(d, "exists", "boot.velx")) then
eeprom.setData(d..";boot.velx")
boot_velx(d, "boot.velx")
end
end
end