256 lines
6.5 KiB
Lua
256 lines
6.5 KiB
Lua
local chunkSize = 32768
|
|
if jit then
|
|
chunkSize = 4092
|
|
end
|
|
|
|
print("Using chunk size "..chunkSize)
|
|
|
|
local function encodeUTF8(asciiText)
|
|
local utf8Text = ""
|
|
|
|
for i=1, #asciiText, chunkSize do
|
|
utf8Text = utf8Text..utf8.char(string.byte(asciiText, i, math.min(i + (chunkSize-1), #asciiText)))
|
|
end
|
|
|
|
return utf8Text
|
|
end
|
|
|
|
local function decodeUTF8(utf8Text)
|
|
local asciiText = ""
|
|
|
|
local ok, t = pcall(function()
|
|
return string.char(utf8.codepoint(utf8Text, 1, #utf8Text))
|
|
end)
|
|
|
|
if ok then
|
|
asciiText = t
|
|
else
|
|
local ok2, err = pcall(function()
|
|
for _, codepoint in utf8.codes(utf8Text) do
|
|
if codepoint < 256 then
|
|
asciiText = asciiText .. string.char(codepoint)
|
|
else
|
|
asciiText = asciiText .. "?"
|
|
end
|
|
end
|
|
end)
|
|
|
|
if not ok2 then
|
|
_G.debugCurrentText = asciiText
|
|
_G.debugTextInput = utf8Text
|
|
|
|
error(err, 2)
|
|
end
|
|
end
|
|
|
|
return asciiText
|
|
end
|
|
|
|
|
|
local function encodeAll(...)
|
|
local tbl = table.pack(...)
|
|
for k,v in pairs(tbl) do
|
|
if type(v) == "string" and not utf8.len(v) then
|
|
tbl[k] = encodeUTF8(v)
|
|
end
|
|
end
|
|
|
|
return table.unpack(tbl, 1, tbl.n)
|
|
end
|
|
|
|
local function decodeAll(...)
|
|
local tbl = table.pack(...)
|
|
for k,v in pairs(tbl) do
|
|
if type(v) == "string" then
|
|
tbl[k] = decodeUTF8(v)
|
|
end
|
|
end
|
|
|
|
return table.unpack(tbl, 1, tbl.n)
|
|
end
|
|
|
|
|
|
|
|
local function extractVersion(str)
|
|
local version = str:match("ComputerCraft (%d+%.%d+%.%d+)")
|
|
return version
|
|
end
|
|
|
|
local function isVersionAbove(version1, version2)
|
|
local function splitVersion(version)
|
|
local parts = {}
|
|
for part in version:gmatch("(%d+)") do
|
|
table.insert(parts, tonumber(part))
|
|
end
|
|
return parts
|
|
end
|
|
|
|
local v1Parts = splitVersion(version1)
|
|
local v2Parts = splitVersion(version2)
|
|
|
|
for i = 1, math.max(#v1Parts, #v2Parts) do
|
|
local v1 = v1Parts[i] or 0
|
|
local v2 = v2Parts[i] or 0
|
|
if v1 > v2 then
|
|
return true
|
|
elseif v1 < v2 then
|
|
return false
|
|
end
|
|
end
|
|
|
|
return true -- They are equal if all parts are equal
|
|
end
|
|
|
|
if isVersionAbove(extractVersion(_HOST), "1.109") then
|
|
print("NOTE: Enabling text-mode conversion")
|
|
local fopen = fs.open
|
|
|
|
function fs.open(path, mode)
|
|
local f = fopen(path, mode)
|
|
if not f then return nil end
|
|
|
|
local customHandle = {}
|
|
|
|
for k,v in pairs(f) do
|
|
if mode:find("b") then
|
|
customHandle[k] = function(...) return v(...) end
|
|
else
|
|
customHandle[k] = function(...) return decodeAll(v(encodeAll(...))) end
|
|
end
|
|
end
|
|
|
|
return customHandle
|
|
end
|
|
else
|
|
print("NOTE: Disabling text-mode conversion")
|
|
end
|
|
|
|
local lStore = {}
|
|
|
|
local hpost = function(...)
|
|
while true do
|
|
local ret = table.pack(http.post(...))
|
|
if not ret[1] then
|
|
os.sleep(0.5)
|
|
else
|
|
badConn = false
|
|
return table.unpack(ret, 1, ret.n)
|
|
end
|
|
end
|
|
end
|
|
|
|
function lStore.run(path)
|
|
print("Downloading " .. path .. "...")
|
|
local f = http.get("https://git.befatorinc.de/Befator-Computing-Systems/ClientOS/raw/branch/main/" .. path).readAll()
|
|
local func,err = loadstring(f,nil,_ENV)
|
|
if not func then
|
|
print(err)
|
|
return false,err
|
|
else
|
|
_G.debugfunc = func
|
|
_G.debugpath = path
|
|
return func()
|
|
end
|
|
end
|
|
|
|
function lStore.store(path)
|
|
print("Downloading " .. path .. "...")
|
|
local file = fs.open(path, "w")
|
|
file.write(http.get("https://git.befatorinc.de/Befator-Computing-Systems/ClientOS/raw/branch/main/" .. path).readAll())
|
|
file.close()
|
|
end
|
|
|
|
print("Running lUtils...")
|
|
lStore.run("LevelOS/startup/lUtils.lua")
|
|
|
|
local oTerm = term.current()
|
|
local nTerm = window.create(term.current(),1,1,term.getSize())
|
|
|
|
term.redirect(nTerm)
|
|
local function render()
|
|
local w,h = nTerm.getSize()
|
|
local oW,oH = oTerm.getSize()
|
|
if oW ~= w or oH ~= h then
|
|
nTerm.reposition(1,1,oW,oH)
|
|
end
|
|
w,h = nTerm.getSize()
|
|
for t=0,15,1 do
|
|
oTerm.setPaletteColor(2^t,table.unpack({nTerm.getPaletteColor(2^t)}))
|
|
end
|
|
local ocursor = {nTerm.getCursorPos()}
|
|
local otext = nTerm.getCursorBlink()
|
|
oTerm.setCursorBlink(false)
|
|
for t=1,h do
|
|
oTerm.setCursorPos(1,t)
|
|
oTerm.blit(nTerm.getLine(t))
|
|
end
|
|
oTerm.setTextColor(nTerm.getTextColor())
|
|
oTerm.setCursorBlink(otext)
|
|
oTerm.setCursorPos(table.unpack(ocursor))
|
|
end
|
|
|
|
print("Grabbing bigfont...")
|
|
lStore.store("bigfont")
|
|
_G.bigfont = loadfile("bigfont",_ENV)()
|
|
|
|
local cor = coroutine.create(
|
|
function()
|
|
print("Running installer...")
|
|
os.sleep(0.5)
|
|
|
|
lStore.store("installer/loadingicon.lua")
|
|
lStore.store("installer/license.lua")
|
|
lStore.store("installer/makebig.lua")
|
|
lStore.store("installer/licensenext.lua")
|
|
lStore.store("installer/LevelOS_Minimal.lua")
|
|
lStore.store("installer/Package_Click.lua")
|
|
lStore.store("installer/LevelOS_Full.lua")
|
|
lStore.store("installer/checkbox.lua")
|
|
lStore.store("installer/license_checkbox.lua")
|
|
lStore.store("installer/installer.lua")
|
|
lStore.store("installer/changecolor.lua")
|
|
lStore.store("installer/next.lua")
|
|
lStore.store("installer/LevelOS_Custom.lua")
|
|
lStore.store("installer/back.lua")
|
|
lStore.store("installer/Package_Update.lua")
|
|
lStore.store("installer/packagenextclicky.lua")
|
|
lStore.store("installer/install.lua")
|
|
lStore.store("installer/corclicky.lua")
|
|
lStore.store("installer/packagenext.lua")
|
|
lStore.store("installer/licensenextclicky.lua")
|
|
|
|
lStore.store("security.lua")
|
|
lStore.store("bios.lua")
|
|
|
|
local ok, err = pcall(function() lStore.run("Installer.sgui") end)
|
|
if not ok then
|
|
printError(err)
|
|
print("Press a key to continue...")
|
|
os.sleep(1)
|
|
os.pullEvent("key")
|
|
else
|
|
print("Done")
|
|
end
|
|
end
|
|
)
|
|
|
|
coroutine.resume(cor)
|
|
render()
|
|
|
|
while coroutine.status(cor) ~= "dead" do
|
|
local e = table.pack(os.pullEventRaw())
|
|
if isVersionAbove(extractVersion(_HOST), "1.109") and e[1] == "http_success" then
|
|
local h = e[3]
|
|
|
|
e[3] = {}
|
|
|
|
for k,v in pairs(h) do
|
|
e[3][k] = function(...) return decodeAll(v(encodeAll(...))) end
|
|
end
|
|
end
|
|
|
|
coroutine.resume(cor, table.unpack(e, 1, e.n))
|
|
render()
|
|
coroutine.resume(cor, "extra_update")
|
|
render()
|
|
end |