mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-07 19:52:40 +01:00
Added support for OpenOS booting in EFI filesystem selection
This commit is contained in:
parent
43fb59d56a
commit
322d3cb59e
106
EFI/Full.lua
106
EFI/Full.lua
@ -1,26 +1,24 @@
|
||||
|
||||
local stringsMain, stringsInit, stringsChangeLabel, stringKeyDown, stringsFilesystem, colorsTitle, colorsBackground, colorsText, colorsSelectionBackground, colorsSelectionText, componentProxy, componentList, pullSignal, uptime, tableInsert, mathMax, mathMin, mathHuge, mathFloor = "MineOS EFI", "/OS.lua", "Change label", "key_down", "filesystem", 0x2D2D2D, 0xE1E1E1, 0x878787, 0x878787, 0xE1E1E1, component.proxy, component.list, computer.pullSignal, computer.uptime, table.insert, math.max, math.min, math.huge, math.floor
|
||||
local stringsMain, stringsChangeLabel, stringKeyDown, stringsFilesystem, colorsTitle, colorsBackground, colorsText, colorsSelectionBackground, colorsSelectionText, componentProxy, componentList, pullSignal, uptime, tableInsert, mathMax, mathMin, mathHuge, mathFloor = "MineOS EFI", "Change label", "key_down", "filesystem", 0x2D2D2D, 0xE1E1E1, 0x878787, 0x878787, 0xE1E1E1, component.proxy, component.list, computer.pullSignal, computer.uptime, table.insert, math.max, math.min, math.huge, math.floor
|
||||
|
||||
local eeprom, gpu, internetAddress = componentProxy(componentList("eeprom")()), componentProxy(componentList("gpu")()), componentList("internet")()
|
||||
|
||||
local shutdown, gpuSet, gpuFill, eepromSetData, eepromGetData, screenWidth, screenHeight, curentBackground, currentForeground = computer.shutdown, gpu.set, gpu.fill, eeprom.setData, eeprom.getData, gpu.getResolution()
|
||||
local shutdown, gpuSet, gpuSetBackground, gpuSetForeground, gpuFill, eepromSetData, eepromGetData, screenWidth, screenHeight = computer.shutdown, gpu.set, gpu.setBackground, gpu.setForeground, gpu.fill, eeprom.setData, eeprom.getData, gpu.getResolution()
|
||||
|
||||
local resetColors, setBackground, setForeground, restrict =
|
||||
function()
|
||||
curentBackground, currentForeground = nil, nil
|
||||
end,
|
||||
function(color)
|
||||
if color ~= curentBackground then
|
||||
gpu.setBackground(color)
|
||||
curentBackground = color
|
||||
end
|
||||
end,
|
||||
function(color)
|
||||
if color ~= currentForeground then
|
||||
gpu.setForeground(color)
|
||||
currentForeground = color
|
||||
end
|
||||
end,
|
||||
local OSList, restrict, rectangle, centrizedText, menuElement =
|
||||
{
|
||||
{
|
||||
"/OS.lua",
|
||||
function()
|
||||
end
|
||||
},
|
||||
{
|
||||
"/init.lua",
|
||||
function()
|
||||
computer.getBootAddress, computer.setBootAddress = eepromGetData, eepromSetData
|
||||
end
|
||||
}
|
||||
},
|
||||
function(text, limit, skip)
|
||||
if #text < limit then
|
||||
text = text .. string.rep(" ", limit - #text)
|
||||
@ -29,16 +27,14 @@ local resetColors, setBackground, setForeground, restrict =
|
||||
end
|
||||
|
||||
return text .. (skip and "" or " ")
|
||||
end
|
||||
|
||||
local rectangle, centrizedText, menuElement =
|
||||
end,
|
||||
function(x, y, width, height, color)
|
||||
setBackground(color)
|
||||
gpuSetBackground(color)
|
||||
gpuFill(x, y, width, height, " ")
|
||||
end,
|
||||
function(y, foreground, text)
|
||||
local x = mathFloor(screenWidth / 2 - #text / 2)
|
||||
setForeground(foreground)
|
||||
gpuSetForeground(foreground)
|
||||
gpuSet(x, y, text)
|
||||
end,
|
||||
function(text, callback, breakLoop)
|
||||
@ -86,29 +82,44 @@ local function executeString(...)
|
||||
end
|
||||
end
|
||||
|
||||
resetColors()
|
||||
status(stringsMain, reason, 1)
|
||||
end
|
||||
|
||||
local loadInit, menuBack, menu, input =
|
||||
local boot, menuBack, menu, input =
|
||||
function(proxy)
|
||||
status(stringsMain, "Booting from " .. proxy.address)
|
||||
for i = 1, #OSList do
|
||||
if proxy.exists(OSList[i][1]) then
|
||||
status(stringsMain, "Booting from " .. proxy.address)
|
||||
|
||||
local handle, data, chunk, success, reason = proxy.open(stringsInit, "rb"), "", ""
|
||||
repeat
|
||||
chunk = proxy.read(handle, mathHuge)
|
||||
data = data .. (chunk or "")
|
||||
until not chunk
|
||||
-- Updating current EEPROM boot address if it's differs from given proxy address
|
||||
if eepromGetData() ~= proxy.address then
|
||||
eepromSetData(proxy.address)
|
||||
end
|
||||
|
||||
proxy.close(handle)
|
||||
-- Running OS pre-boot function
|
||||
OSList[i][2]()
|
||||
|
||||
executeString(data, "=" .. stringsInit)
|
||||
-- Reading boot file
|
||||
local handle, data, chunk, success, reason = proxy.open(OSList[i][1], "rb"), ""
|
||||
repeat
|
||||
chunk = proxy.read(handle, mathHuge)
|
||||
data = data .. (chunk or "")
|
||||
until not chunk
|
||||
|
||||
proxy.close(handle)
|
||||
|
||||
-- Running boot file
|
||||
executeString(data, "=" .. OSList[i][1])
|
||||
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end,
|
||||
function()
|
||||
return menuElement("Back", nil, 1)
|
||||
end,
|
||||
function(titleText, elements)
|
||||
local spacing, selectedElement, maxLength = 2, 1, 0
|
||||
local selectedElement, maxLength = 1, 0
|
||||
for i = 1, #elements do
|
||||
maxLength = math.max(maxLength, #elements[i].s)
|
||||
end
|
||||
@ -121,11 +132,11 @@ local loadInit, menuBack, menu, input =
|
||||
|
||||
if i == selectedElement then
|
||||
rectangle(mathFloor(screenWidth / 2 - maxLength / 2) - 2, y, maxLength + 4, 1, colorsSelectionBackground)
|
||||
setForeground(colorsSelectionText)
|
||||
gpuSetForeground(colorsSelectionText)
|
||||
gpuSet(x, y, elements[i].s)
|
||||
gpuSetBackground(colorsBackground)
|
||||
else
|
||||
setBackground(colorsBackground)
|
||||
setForeground(colorsText)
|
||||
gpuSetForeground(colorsText)
|
||||
gpuSet(x, y, elements[i].s)
|
||||
end
|
||||
|
||||
@ -155,7 +166,7 @@ local loadInit, menuBack, menu, input =
|
||||
while 1 do
|
||||
eblo = prefix .. text
|
||||
gpuFill(1, y, screenWidth, 1, " ")
|
||||
setForeground(colorsText)
|
||||
gpuSetForeground(colorsText)
|
||||
gpuSet(mathFloor(screenWidth / 2 - #eblo / 2), y, eblo .. (state and "█" or ""))
|
||||
|
||||
eventData = {pullSignal(0.5)}
|
||||
@ -181,7 +192,7 @@ local loadInit, menuBack, menu, input =
|
||||
end
|
||||
|
||||
gpu.bind(componentList("screen")(), true)
|
||||
status(stringsMain, "Hold Alt to show boot options menu")
|
||||
status(stringsMain, "Hold Alt to show boot options")
|
||||
|
||||
local deadline, eventData = uptime() + 1
|
||||
while uptime() < deadline do
|
||||
@ -221,13 +232,13 @@ while uptime() < deadline do
|
||||
end, 1))
|
||||
end
|
||||
|
||||
tableInsert(filesystemOptions, 1, menuElement("Set as startup", function()
|
||||
tableInsert(filesystemOptions, 1, menuElement("Set as bootable", function()
|
||||
eepromSetData(address)
|
||||
end, 1))
|
||||
|
||||
menu(label .. " (" .. address .. ")", filesystemOptions)
|
||||
end
|
||||
, 1)
|
||||
end, 1
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@ -254,7 +265,7 @@ while uptime() < deadline do
|
||||
if result then
|
||||
data = data .. result
|
||||
else
|
||||
handle:close()
|
||||
handle.close()
|
||||
|
||||
if reason then
|
||||
status(stringsMain, reason, 1)
|
||||
@ -276,14 +287,11 @@ while uptime() < deadline do
|
||||
end
|
||||
|
||||
local proxy = componentProxy(eepromGetData())
|
||||
if proxy and proxy.exists(stringsInit) then
|
||||
loadInit(proxy)
|
||||
else
|
||||
if not (proxy and boot(proxy)) then
|
||||
for address in componentList(stringsFilesystem) do
|
||||
proxy = componentProxy(address)
|
||||
if proxy.exists(stringsInit) then
|
||||
eepromSetData(address)
|
||||
loadInit(proxy)
|
||||
|
||||
if boot(proxy) then
|
||||
break
|
||||
else
|
||||
proxy = nil
|
||||
|
||||
@ -1 +1 @@
|
||||
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s="MineOS EFI","/OS.lua","Change label","key_down","filesystem",0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1,component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local t,u,v=k(l("eeprom")()),k(l("gpu")()),l("internet")()local w,x,y,z,A,B,C,D,E=computer.shutdown,u.set,u.fill,t.setData,t.getData,u.getResolution()local F,G,H,I=function()D,E=nil,nil end,function(J)if J~=D then u.setBackground(J)D=J end end,function(J)if J~=E then u.setForeground(J)E=J end end,function(K,L,M)if#K<L then K=K..string.rep(" ",L-#K)else K=K:sub(1,L)end;return K..(M and""or" ")end;local N,O,P=function(Q,R,S,T,J)G(J)y(Q,R,S,T," ")end,function(R,U,K)local Q=s(B/2-#K/2)H(U)x(Q,R,K)end,function(K,V,W)return{s=K,c=V,b=W}end;local function X(R,Y)R=s(C/2-R/2)N(1,1,B,C,g)O(R,f,Y)return R+2 end;local function Z(Y,_,a0)local a1={}for a2 in _:gmatch("[^\r\n]+")do a1[#a1+1]=a2:gsub("\t"," ")end;local R=X(#a1,Y)for a3=1,#a1 do O(R,h,a1[a3])R=R+1 end;if a0 then repeat a0=m()until a0==d or a0=="touch"end end;local function a4(...)local a5,a6=load(...)if a5 then a5,a6=xpcall(a5,debug.traceback)if a5 then return end end;F()Z(a,a6,1)end;local a7,a8,a9,aa=function(ab)Z(a,"Booting from "..ab.address)local ac,ad,ae,af,a6=ab.open(b,"rb"),"",""repeat ae=ab.read(ac,r)ad=ad..(ae or"")until not ae;ab.close(ac)a4(ad,"="..b)end,function()return P("Back",nil,1)end,function(Y,ag)local ah,ai,aj=2,1,0;for a3=1,#ag do aj=math.max(aj,#ag[a3].s)end;while 1 do local R,Q,ak=X(#ag+2,Y)for a3=1,#ag do Q=s(B/2-#ag[a3].s/2)if a3==ai then N(s(B/2-aj/2)-2,R,aj+4,1,i)H(j)x(Q,R,ag[a3].s)else G(g)H(h)x(Q,R,ag[a3].s)end;R=R+1 end;ak={m()}if ak[1]==d then if ak[4]==200 and ai>1 then ai=ai-1 elseif ak[4]==208 and ai<#ag then ai=ai+1 elseif ak[4]==28 then if ag[ai].c then ag[ai].c()end;if ag[ai].b then return end end end end end,function(R,al)local K,am,an,ak,ao="",true;while 1 do an=al..K;y(1,R,B,1," ")H(h)x(s(B/2-#an/2),R,an..(am and"█"or""))ak={m(0.5)}if ak[1]==d then if ak[4]==28 then return K elseif ak[4]==14 then K=K:sub(1,-2)else ao=unicode.char(ak[3])if ao:match("^[%w%d%p%s]+")then K=K..ao end end;am=true elseif ak[1]=="clipboard"then K=K..ak[3]elseif not ak[1]then am=not am end end end;u.bind(l("screen")(),true)Z(a,"Hold Alt to show boot options menu")local ap,ak=n()+1;while n()<ap do ak={m(ap-n())}if ak[1]==d and ak[4]==56 then local aq={P("Disk management",function()local ar,as={a8()},A()for at in l(e)do local ab=k(at)local au,av=ab.getLabel()or"Unnamed",ab.isReadOnly()o(ar,1,P((at==as and"> "or" ")..I(au,10)..I(ab.spaceTotal()>1048576 and"HDD"or ab.spaceTotal()>65536 and"FDD"or"SYS",3)..I(av and"R"or"R/W",3)..at:sub(1,8).." "..I(string.format("%.2f",ab.spaceUsed()/ab.spaceTotal()*100).."%",6,1),function()local aw={a8()}if not av then o(aw,1,P(c,function()ab.setLabel(aa(X(2,c),"Enter new name: "))end,1))o(aw,2,P("Format",function()Z(a,"Formatting filesystem "..at)for ax,ay in ipairs(ab.list("/"))do ab.remove(ay)end;Z(a,"Formatting finished",1)end,1))end;o(aw,1,P("Set as startup",function()z(at)end,1))a9(au.." ("..at..")",aw)end,1))end;a9("Select filesystem",ar)end),P("Shutdown",function()w()end),a8()}if v then o(aq,2,P("Internet recovery",function()local ac,ad,a5,a6=k(v).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"),""if ac then Z(a,"Downloading recovery script")while 1 do a5,a6=ac.read(r)if a5 then ad=ad..a5 else ac:close()if a6 then Z(a,a6,1)else a4(ad,"=string")end;break end end else Z(a,"invalid URL-address",1)end end))end;a9(a,aq)end end;local ab=k(A())if ab and ab.exists(b)then a7(ab)else for at in l(e)do ab=k(at)if ab.exists(b)then z(at)a7(ab)break else ab=nil end end;if not ab then Z(a,"No bootable mediums found",1)end end;w()
|
||||
local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r="MineOS EFI","Change label","key_down","filesystem",0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1,component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local s,t,u=j(k("eeprom")()),j(k("gpu")()),k("internet")()local v,w,x,y,z,A,B,C,D=computer.shutdown,t.set,t.setBackground,t.setForeground,t.fill,s.setData,s.getData,t.getResolution()local E,F,G,H,I={{"/OS.lua",function()end},{"/init.lua",function()computer.getBootAddress,computer.setBootAddress=B,A end}},function(J,K,L)if#J<K then J=J..string.rep(" ",K-#J)else J=J:sub(1,K)end;return J..(L and""or" ")end,function(M,N,O,P,Q)x(Q)z(M,N,O,P," ")end,function(N,R,J)local M=r(C/2-#J/2)y(R)w(M,N,J)end,function(J,S,T)return{s=J,c=S,b=T}end;local function U(N,V)N=r(D/2-N/2)G(1,1,C,D,f)H(N,e,V)return N+2 end;local function W(V,X,Y)local Z={}for _ in X:gmatch("[^\r\n]+")do Z[#Z+1]=_:gsub("\t"," ")end;local N=U(#Z,V)for a0=1,#Z do H(N,g,Z[a0])N=N+1 end;if Y then repeat Y=l()until Y==c or Y=="touch"end end;local function a1(...)local a2,a3=load(...)if a2 then a2,a3=xpcall(a2,debug.traceback)if a2 then return end end;W(a,a3,1)end;local a4,a5,a6,a7=function(a8)for a0=1,#E do if a8.exists(E[a0][1])then W(a,"Booting from "..a8.address)if B()~=a8.address then A(a8.address)end;E[a0][2]()local a9,aa,ab,ac,a3=a8.open(E[a0][1],"rb"),""repeat ab=a8.read(a9,q)aa=aa..(ab or"")until not ab;a8.close(a9)a1(aa,"="..E[a0][1])return 1 end end end,function()return I("Back",nil,1)end,function(V,ad)local ae,af=1,0;for a0=1,#ad do af=math.max(af,#ad[a0].s)end;while 1 do local N,M,ag=U(#ad+2,V)for a0=1,#ad do M=r(C/2-#ad[a0].s/2)if a0==ae then G(r(C/2-af/2)-2,N,af+4,1,h)y(i)w(M,N,ad[a0].s)x(f)else y(g)w(M,N,ad[a0].s)end;N=N+1 end;ag={l()}if ag[1]==c then if ag[4]==200 and ae>1 then ae=ae-1 elseif ag[4]==208 and ae<#ad then ae=ae+1 elseif ag[4]==28 then if ad[ae].c then ad[ae].c()end;if ad[ae].b then return end end end end end,function(N,ah)local J,ai,aj,ag,ak="",true;while 1 do aj=ah..J;z(1,N,C,1," ")y(g)w(r(C/2-#aj/2),N,aj..(ai and"█"or""))ag={l(0.5)}if ag[1]==c then if ag[4]==28 then return J elseif ag[4]==14 then J=J:sub(1,-2)else ak=unicode.char(ag[3])if ak:match("^[%w%d%p%s]+")then J=J..ak end end;ai=true elseif ag[1]=="clipboard"then J=J..ag[3]elseif not ag[1]then ai=not ai end end end;t.bind(k("screen")(),true)W(a,"Hold Alt to show boot options")local al,ag=m()+1;while m()<al do ag={l(al-m())}if ag[1]==c and ag[4]==56 then local am={I("Disk management",function()local an,ao={a5()},B()for ap in k(d)do local a8=j(ap)local aq,ar=a8.getLabel()or"Unnamed",a8.isReadOnly()n(an,1,I((ap==ao and"> "or" ")..F(aq,10)..F(a8.spaceTotal()>1048576 and"HDD"or a8.spaceTotal()>65536 and"FDD"or"SYS",3)..F(ar and"R"or"R/W",3)..ap:sub(1,8).." "..F(string.format("%.2f",a8.spaceUsed()/a8.spaceTotal()*100).."%",6,1),function()local as={a5()}if not ar then n(as,1,I(b,function()a8.setLabel(a7(U(2,b),"Enter new name: "))end,1))n(as,2,I("Format",function()W(a,"Formatting filesystem "..ap)for at,au in ipairs(a8.list("/"))do a8.remove(au)end;W(a,"Formatting finished",1)end,1))end;n(as,1,I("Set as bootable",function()A(ap)end,1))a6(aq.." ("..ap..")",as)end,1))end;a6("Select filesystem",an)end),I("Shutdown",function()v()end),a5()}if u then n(am,2,I("Internet recovery",function()local a9,aa,a2,a3=j(u).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"),""if a9 then W(a,"Downloading recovery script")while 1 do a2,a3=a9.read(q)if a2 then aa=aa..a2 else a9.close()if a3 then W(a,a3,1)else a1(aa,"=string")end;break end end else W(a,"invalid URL-address",1)end end))end;a6(a,am)end end;local a8=j(B())if not(a8 and a4(a8))then for ap in k(d)do a8=j(ap)if a4(a8)then break else a8=nil end end;if not a8 then W(a,"No bootable mediums found",1)end end;v()
|
||||
@ -508,7 +508,7 @@ local function iconAnalyseExtension(icon, launchers)
|
||||
if icon.extension == ".lnk" then
|
||||
icon.shortcutPath = system.readShortcut(icon.path)
|
||||
icon.shortcutExtension = filesystem.extension(icon.shortcutPath)
|
||||
icon.shortcutIsDirectory = filesystem.isDirectory(icon.shortcutPath)
|
||||
icon.shortcutIsDirectory = icon.shortcutPath:sub(-1) == "/"
|
||||
icon.isShortcut = true
|
||||
|
||||
local shortcutIcon = iconAnalyseExtension(
|
||||
@ -580,8 +580,8 @@ function system.icon(x, y, path, textColor, selectionColor)
|
||||
}
|
||||
|
||||
icon.path = path
|
||||
icon.extension = filesystem.extension(icon.path)
|
||||
icon.isDirectory = filesystem.isDirectory(icon.path)
|
||||
icon.extension = filesystem.extension(path)
|
||||
icon.isDirectory = path:sub(-1) == "/"
|
||||
icon.name = icon.isDirectory and filesystem.name(path):sub(1, -2) or filesystem.name(path)
|
||||
icon.nameWithoutExtension = filesystem.hideExtension(icon.name)
|
||||
icon.isShortcut = false
|
||||
@ -879,7 +879,7 @@ local function iconOnRightClick(icon, e1, e2, e3, e4)
|
||||
for i = 1, #list do
|
||||
local path = paths.system.applications .. list[i]
|
||||
|
||||
if filesystem.isDirectory(path) and filesystem.extension(list[i]) == ".app" then
|
||||
if path:sub(-1) == "/" and filesystem.extension(list[i]) == ".app" then
|
||||
subMenu:addItem(filesystem.hideExtension(list[i])).onTouch = function()
|
||||
setAssociation(path)
|
||||
end
|
||||
@ -2572,7 +2572,7 @@ function system.authorize()
|
||||
local userList = filesystem.list(paths.system.users)
|
||||
local i = 1
|
||||
while i <= #userList do
|
||||
if filesystem.isDirectory(paths.system.users .. userList[i]) then
|
||||
if userList[i]:sub(-1) == "/" then
|
||||
i = i + 1
|
||||
else
|
||||
table.remove(userList, i)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user