ClientOS/installer/installer.lua
2025-10-23 00:21:18 +02:00

115 lines
2.8 KiB
Lua

local function dothething()
fs.move("tmp/bigfont", "bigfont")
_G.bigfont = loadfile("bigfont",_ENV)()
local function wordwrap(str)
local x,y = term.getCursorPos()
local tW,tH = term.getSize()
for w in str:gmatch("%S+") do
local x1,y1 = term.getCursorPos()
if x1+(#w*3) >= tW then
bigfont.bigPrint(" ")
local x2,y2 = term.getCursorPos()
term.setCursorPos(x,y2)
end
bigfont.bigWrite(w.." ")
end
end
--local ico = lUtils.asset.load("User/Cloud/Images/New_Loading.limg") -- replace with actual filepath later
fs.move("tmp/LevelOS/assets/loading.limg", "LevelOS/assets/loading.limg")
local file = fs.open("LevelOS/assets/loading.limg")
local f = file.readAll()
file.close()
local ico = textutils.unserialize(f)
for t=1,#ico do
for l=1,#ico[t] do
ico[t][l][2] = string.gsub(ico[t][l][2],"T","9")
ico[t][l][3] = string.gsub(ico[t][l][3],"T","9")
end
end
local frame = 1
local prog = 0
local icoX,icoY
local function renderIco(frame)
local f = ico[frame]
for l=1,#f do
term.setCursorPos(icoX,icoY+(l-1))
term.blit(unpack(f[l]))
end
end
local function progress()
while true do
renderIco(frame)
term.setCursorPos(icoX+5,icoY+1)
term.write(math.floor(prog + 0.5).."% complete")
os.sleep(0.1)
frame = frame+1
if frame > #ico then
frame = 1
end
end
end
local function fread(file)
local f = fs.open(file,"r")
local o = f.readAll()
f.close()
return o
end
local function fwrite(file,content)
local f = fs.open(file,"w")
f.write(content)
f.close()
return true
end
local function render()
term.setBackgroundColor(colors.cyan)
term.setTextColor(colors.white)
term.clear()
local w,h = term.getSize()
local x = 2
if w > 51 then
x = math.floor(x+((w-51)/4))
end
term.setCursorPos(x,3)
wordwrap("Installing BefatorOS")
bigfont.bigPrint(" ")
local x1,y1 = term.getCursorPos()
term.setCursorPos(x,y1+2)
print("This might take a while. Don't turn off your computer.")
local x1,y1 = term.getCursorPos()
icoX,icoY = x,y1+1
-- perhaps a cancel button if i ever feel like it
end
render()
local function events()
while true do
local e = {os.pullEvent()}
-- process things if buttons
if e[1] == "term_resize" then
render()
end
end
end
local function downloader()
for i=1,100 do
os.sleep(math.random())
prog = i
end
fs.move("tmp/stage2-install.lua", "real_startup.lua")
os.sleep(2)
os.reboot()
end
parallel.waitForAny(events,progress,downloader)
end
local ok,err = pcall(dothething)
if not ok then
term.setCursorPos(1,1)
term.setTextColor(colors.red)
term.write(err)
end