Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dev=false;defaultPath=nil;WaitTime=15;local a=0;function LoadCFG()if fs.exists(".bcfg")then local f=fs.open(".bcfg",'r')local b=f.readAll()f.close()ion=textutils.unserialize(b)for c,d in pairs(ion)do if dev then print(tostring(c).." = "..tostring(d))end;ls=loadstring(c.." = "..tostring(d))setfenv(ls,getfenv())ls()end;if dev then sleep(.5)end end end;function ViewInsert()if fs.exists("/Views")~=true then fs.makeDir("/Views")end;if fs.exists("/Views/main.view")~=true then local f=fs.open("/Views/main.view",'w')local e=[[{
- Children={
- {
- X=1,
- Width="100%",
- Y=2,
- Name="HelloLabel",
- Type="Label",
- Text="Bootloader Setup",
- Align="Center",
- },
- {
- X=2,
- Y=4,
- Name="DebugMode",
- Type="Button",
- Text="Debug Mode: Disabled",
- },
- {
- X="1",
- Y="100%",
- Align = "Right",
- Name="Save",
- Type="Button",
- Text="Save",
- },
- {
- X=2,
- Y=6,
- Width=22,
- Type="TextBox",
- Name="DPath",
- Placeholder="Default Path",
- Active=false
- },
- {
- X=2,
- Y=8,
- Width=22,
- Type="TextBox",
- Name="WaitT",
- Placeholder="Wait Time",
- Active=false,
- },
- {
- X="88%",
- Y="100%",
- Align = "Left",
- Name="Reboot",
- Type="Button",
- Text="Reboot",
- },
- },
- BackgroundColour='white'
- } ]]f.write(e)f.close()end end;function startup()if fs.exists('startup')then local f=fs.open('startup','r')local g=f.readLine()debug(g)if g~="--#--"then fs.move('startup','startup.boot')end end;local f=fs.open(shell.getRunningProgram(),'r')local g=f.readLine()f.close()local f=fs.open(shell.getRunningProgram(),'r')if g=="--#--"then debug('sgrp = --#--')local h=fs.open('startup','w')h.write(f.readAll())h.close()end;f.close()end;function debug(i)if dev then print(i)end end;function cfill(j)if term.isColor()~=true then j=colors.black end;term.setCursorPos(1,1)term.setBackgroundColor(j)term.setTextColor(j)for k=1,24 do print("=========================================================")end;term.setCursorPos(1,1)end;function kt()r=true;debug('Keypress Listener Started')x,y=term.getSize()x1,y1=term.getCursorPos()term.setCursorPos(x/2-11,y)print("DELETE for more options")if term.isColor()then term.setCursorPos(x/2-10,y-2)print("ESCAPE to enter setup")end;while true do os.startTimer(.1)term.setCursorPos(1,y1+1)print("Time Remaining: ")term.setCursorPos(17,y1+1)print(" ")term.setCursorPos(17,y1+1)print(WaitTime-a)local d,c=os.pullEvent()r='Continue'if d=='key'then if c==keys.enter then r='Continue'debug('Enter Pressed')break end;if c==keys.delete then r="Menu"debug('Delete Pressed')break end;if c==1 then r="Setup"debug("Escape Pressed")break end end;sleep(.1)a=a+1;if a>=WaitTime then break end end;return r end;function find()local l={}if fs then local m={'boot','start','startup','load','bin'}for c,d in pairs(m)do debug('searching *.'..d)local n={}n=fs.find('*.'..d)for o,p in pairs(n)do table.insert(l,p)end end;debug('')else error("NO FS API")end;return l end;function select(q)debug(q[1].." Selected")return q[1]end;function exec(t)local f=fs.open(t,'r')local r=f.readAll()f.close()local j=loadstring(r)setfenv(j,getfenv())if term then term.clear()term.setCursorPos(1,1)term.setBackgroundColor(colors.black)cfill(colors.black)term.setTextColor(colors.white)else error("NO TERM API")end;j()end;function boot()local r="Continue"print('Searching...')local f=find()if#f<1 then term.setTextColor(colors.red)print('No Bootable Medium Found')term.setTextColor(colors.white)sleep(2)r=false else local u=''if#f>1 or#f<1 then u='s'end;print('found '..#f.." file"..u)for d,k in pairs(f)do print(' '..k)end;local v=select(f)if defaultPath~=nil and#defaultPath>=1 then v=defaultPath end;print('Selecting: '..v)debug('')local c=kt()if c=="Continue"then exec(v)elseif c=="Menu"then r="Menu"elseif c=="Setup"then r="Setup"end end;return r end;function setup()local w='/'if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua',false)elseif fs.exists(w..'/Bedrock')then os.loadAPI(w..'/Bedrock')else if http then print('Downloading Bedrock...')local p=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if p then local f=fs.open(w..'/Bedrock','w')f.write(p.readAll())f.close()p.close()os.loadAPI(w..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?')end else error('This program needs to download Bedrock to work. Please enable HTTP.')end end;if Bedrock then Bedrock.BasePath=w;Bedrock.ProgramPath=shell.getRunningProgram()end;ViewInsert()local z=Bedrock:Initialise()z:Run(function()DevMode=dev;if DevMode==false then z:GetObject('DebugMode').Text="Debug Mode: Disabled"else z:GetObject('DebugMode').Text="Debug Mode: Enabled"end;z:GetObject('DebugMode').OnClick=function(A,B,C,x,y)if DevMode==false then DevMode=true else DevMode=false end;dev=DevMode;if DevMode==false then z:GetObject('DebugMode').Text="Debug Mode: Disabled"else z:GetObject('DebugMode').Text="Debug Mode: Enabled"end end;z:GetObject('Reboot').OnClick=function(A,B,C,x,y)os.reboot()end;function getpath()local path=z:GetObject('DPath').Text;local safe=false;if path~=nil and fs.exists(path)then safe=true elseif path~=nil and fs.exists(path)~=true then z:DisplayAlertWindow('Error','Invalid Path',{'OK'},function(value)end)safe=false;path=""elseif path==nil then safe=true;path=""end;msg={}msg.safe=safe;msg.path=tostring("'"..path.."'")return msg end;function getwait()local path=z:GetObject('WaitT').Text;local safe=false;if path~=nil and tonumber(path)then safe=true elseif path==""then safe=true;path="15"else z:DisplayAlertWindow('Error','Invalid Wait Time',{'OK'},function(value)end)safe=false;path=""end;msg={}msg.safe=safe;msg.value=path;return msg end;z:GetObject('Save').OnClick=function(A,B,C,x,y)local D=true;local u=getpath()local E=getwait()local path=""local F=""local G={}if u['safe']then path=u['path']else D=false end;if E['safe']then F=E['value']else D=false end;G.dev=DevMode;G.defaultPath=path;G.WaitTime=F;if D then local f=fs.open(".bcfg",'w')f.write(textutils.serialize(G))f.close()end;if D then z:DisplayAlertWindow('Success','Settings Saved',{'OK'},function(value)end)end end end)end;function menu()term.clear()cfill(colors.blue)if term.isColor then term.setBackgroundColor(colors.blue)end;term.setTextColor(colors.white)local x,y=term.getSize()term.setCursorPos(x/2-8,1)print('Select a boot file')local x,y=term.getSize()term.setCursorPos(1,4)dev=false;local f=find()dev=true;for k,d in pairs(f)do print(k..'. '..d)end;print('0. Other')print('')print('')write('#> ')local H=read()if tonumber(H)==0 then write('Path> ')local I=read()if fs.exists(I)then exec(I)else print('file does not exist')sleep(2)menu()end elseif tonumber(H)==nil or tonumber(H)>#f or tonumber(H)<1 then print('Invalid boot file')menu()else local s=f[tonumber(H)]print('Selecting '..s)sleep(1)exec(s)end end;argv={...}if#argv>0 then local J={}if fs.exists('.bcfg')then local K=fs.open('.bcfg','r')J=K.readAll()K.close()J=textutils.unserialise(J)end;for c,d in pairs(argv)do f,s=string.match(d,"(%w+)=(%w+)")debug(f.." "..s)J[f]=s;print("Inserted "..s.." into "..f)end;local K=fs.open('.bcfg','w')K.write(textutils.serialize(J))K.close()else if shell.getRunningProgram()~='startup'or fs.exists('startup')==false then startup()os.reboot()else LoadCFG()local L=boot()if L=="Continue"then elseif L=="Menu"then menu()elseif L=="Setup"then setup()end end end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement