Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local stx, sty = term.getSize()
- local cfile = "/.aloOS"
- local changel = [[
- * 1.3
- - Added scrolling and clicking.
- - More options in sertup.
- * 1.2.23
- - Added reset config.
- - Added reformat computer.
- - Added force upadte.
- * 1.2
- - Fixed startup message. Renamed main file.
- - Added changelog :D.
- - Added recycling.
- * 1.1.5
- - Added the "Power" commands.
- * 1.1
- - Added "Rednet" commands.
- * 1.0.12
- - Bug fixes.
- * 1.0.1
- - Added "System" commands.
- * 1.0
- - First release.
- ]]
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local config = {
- colors = {
- main = colors.lime;
- second = colors.white;
- bg = colors.black;
- };
- controls = {
- click = true;
- scroll = true;
- };
- version = "1.3";
- }
- local function drawlist(title, listr, num)
- clear()
- term.setTextColor(config.colors.main)
- local list = {}
- print(title.."\n")
- for i,v in pairs(listr) do
- list[i] = v
- end
- local start = 1
- local last = #list
- if num > sty - 4 then
- start = num - (sty - 4)
- end
- local cnt = 0
- for i = start, #list do
- if cnt > sty - 4 then
- last = last - 1
- cnt = cnt - 1
- end
- cnt = cnt + 1
- end
- for m = start, last do
- local tor = true
- if tor == true then
- if m == num then
- term.setTextColor(config.colors.second)
- write("[")
- term.setTextColor(config.colors.main)
- write("-")
- term.setTextColor(config.colors.second)
- write("]")
- term.setTextColor(config.colors.main)
- print(" "..list[m])
- else
- term.setTextColor(config.colors.second)
- print("[ ] "..list[m])
- end
- end
- end
- end
- local function getKey()
- local rt = nil
- function lop()
- local e, a1 = os.pullEvent()
- if e == "key" then
- if a1 == 200 then
- rt = "up"
- elseif a1 == 208 then
- rt = "down"
- elseif a1 == 28 then
- rt = "enter"
- else
- lop()
- end
- elseif e == "mouse_scroll" then
- if config.controls.scroll == true then
- if a1 == 1 then
- rt = "down"
- elseif a1 == -1 then
- rt = "up"
- else
- lop()
- end
- else
- lop()
- end
- elseif e == "mouse_click" then
- if config.controls.click == true then
- if a1 == 1 then
- rt = "enter"
- else
- lop()
- end
- else
- lop()
- end
- else
- lop()
- end
- end
- lop()
- repeat sleep(0) until rt ~= nil
- return rt
- end
- local function ch(title, list)
- clear()
- local ind = 1
- local lcopy = list
- drawlist(title, lcopy, ind)
- local rt = nil
- cycle = function()
- local ke = getKey()
- if ke == "up" then
- if ind > 1 then
- ind = ind - 1
- else
- ind = #list
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "down" then
- if ind < #list then
- ind = ind + 1
- else
- ind = 1
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "enter" then
- rt = ind
- end
- end
- cycle()
- repeat sleep(0) until rt ~= nil
- return ind
- end
- local function printcol(txt, color)
- term.setTextColor(color)
- print(txt)
- term.setTextColor(config.colors.second)
- end
- local function listcol(text)
- local cols = {}
- for i,v in pairs(colors) do
- if type(v) == "number" then
- table.insert(cols, i)
- end
- end
- local re = ch(text, cols)
- return colors[cols[re]]
- end
- local function setup()
- while true do
- local pl = ch("Configuration", {"Choose main color", "Choose secondary color", "Choose background color", "Enable/disable click", "Enable/disable scroll", "Exit setup"})
- if pl == 1 then
- config.colors.main = listcol("Please choose a color")
- elseif pl == 2 then
- config.colors.second = listcol("Please choose a color")
- elseif pl == 3 then
- config.colors.bg = listcol("Please choose a color")
- term.setBackgroundColor(config.colors.bg)
- clear()
- elseif pl == 4 then
- local pd = ch("Disable or enable click?", {"Disable", "Enable"})
- if pd == 1 then
- config.controls.click = false
- elseif pd == 2 then
- config.controls.click = true
- end
- elseif pl == 5 then
- local pd = ch("Disable or enable scroll?", {"Disable", "Enable"})
- if pd == 1 then
- config.controls.scroll = false
- elseif pd == 2 then
- config.controls.scroll = true
- end
- elseif pl == 6 then
- break
- end
- end
- end
- local function sep(list, by)
- local newlist = {}
- while true do
- local on = nil
- local done = false
- for i = 1, #list do
- if done == false then
- if string.sub(list, i, i) == by then
- on = i
- done = true
- end
- end
- end
- if on then
- table.insert(newlist, string.sub(list, 1, on - 1))
- list = string.sub(list, on + 1)
- else
- break
- end
- end
- table.insert(newlist, list)
- return newlist
- end
- local function update()
- local res = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( "X7M1GkNW" )
- )
- local sRes = res.readAll()
- res.close()
- if sRes ~= config.version then
- local fr = ch("New update available", {"Update", "Don't update"})
- if fr == 1 then
- local res2 = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( "pwz9u82d" )
- )
- local scr = res2.readAll()
- res2.close()
- local bcols = textutils.serialize(config.colors)
- local bc = fs.open("/bcol", "w")
- bc.write(bcols)
- bc.close()
- local bc2 = fs.open("/bcon", "w")
- bc2.write(textutils.serialize(config.controls))
- bc2.close()
- local sname = shell.getRunningProgram()
- local pl = fs.open(sname, "w")
- pl.write(scr)
- pl.close()
- os.reboot()
- end
- else
- local pe = ch("No updates available", {"Close", "Force update"})
- if pe == 2 then
- local res2 = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( "pwz9u82d" )
- )
- local scr = res2.readAll()
- res2.close()
- local bcols = textutils.serialize(config.colors)
- local bc = fs.open("/bcol", "w")
- bc.write(bcols)
- bc.close()
- local bc2 = fs.open("/bcon", "w")
- bc2.write(textutils.serialize(config.controls))
- bc2.close()
- local sname = shell.getRunningProgram()
- local pl = fs.open(sname, "w")
- pl.write(scr)
- pl.close()
- os.reboot()
- end
- end
- end
- local function savecon()
- local fl = fs.open(cfile.."/config", "w")
- fl.write(textutils.serialize(config))
- fl.close()
- end
- local function loadcon()
- local fl = fs.open(cfile.."/config", "r")
- config = textutils.unserialize(fl.readAll())
- fl.close()
- end
- local function checkports()
- local isp = false
- for i,v in pairs(sides) do
- if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
- isp = true
- end
- end
- return isp
- end
- local function getsys()
- local res2 = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( "U537Qp6w" )
- )
- local prl = textutils.unserialize(res2.readAll())
- res2.close()
- fs.delete(cfile.."/Programs/System")
- fs.makeDir(cfile.."/Programs/System")
- for i,v in pairs(prl) do
- printcol("Downloading "..i, config.colors.main)
- local res2 = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( v )
- )
- local cp = fs.open(cfile.."/Programs/System/"..i, "w")
- cp.write(res2.readAll())
- cp.close()
- res2.close()
- end
- end
- local oldd = fs.delete
- function fs.delete(path)
- path = shell.resolve(path)
- pcall(function()
- fs.copy(path, cfile.."/recycle")
- end)
- oldd(path)
- end
- local function ports()
- for i,v in pairs(sides) do
- rednet.open(v)
- end
- end
- if fs.exists("/bcol") then
- local bc = fs.open("/bcol", "r")
- config.colors = textutils.unserialize(bc.readAll())
- bc.close()
- fs.delete("/bcol")
- end
- if fs.exists("/bcon") then
- local bc = fs.open("/bcon", "r")
- config.controls = textutils.unserialize(bc.readAll())
- bc.close()
- fs.delete("/bcon")
- end
- term.setBackgroundColor(config.colors.bg)
- clear()
- if not fs.exists(cfile) then
- getsys()
- printcol("Alo has detected this being the first time using aloOS", config.colors.main)
- local pl = ch("Alo has detected this being the first time using alOS. Would you like to go through the setup or use default settings?", {"Setup", "Default"})
- if pl == 1 then
- setup()
- end
- printcol("Saving files...", config.colors.main)
- sleep(1)
- fs.makeDir(cfile)
- fs.makeDir(cfile.."/recycle")
- savecon()
- else
- loadcon()
- end
- local tob = false
- local chy = {
- ["System"] = {
- ["Terminal"] = function() tob = true end;
- ["Update"] = function() update() end;
- ["Changelog"] = function()
- local cul = fs.open(cfile.."/changelogChache", "w")
- cul.write(changel)
- cul.close()
- shell.run("edit", cfile.."/changelogChache")
- fs.delete(cfile.."/changelogChache")
- end;
- ["Reset config"] = function()
- local pe = ch("Are you sure you wish to reset configuration?", {"Yes", "No"})
- if pe == 1 then
- fs.delete(cfile)
- os.reboot()
- end
- end;
- ["Reformat computer"] = function()
- local pe = ch("Are you sure you wish to reformat computer?", {"Yes", "No"})
- if pe == 1 then
- for i,v in pairs(fs.list("/")) do
- if v ~= shell.getRunningProgram() and v ~= "rom" then
- pcall(function()
- oldd("/"..v)
- end)
- end
- end
- os.reboot()
- end
- end;
- };
- ["Run setup"] = function() setup() savecon() end;
- ["Power"] = {
- ["Shutdown"] = function() os.shutdown() end;
- ["Reboot"] = function() os.reboot() end;
- };
- ["Rednet"] = {
- ["Open ports"] = function()
- function lpo1()
- if checkports() then
- ports()
- else
- local po = ch("No modem attached", {"Rety", "Cancel"})
- if po == 1 then
- lpo1()
- end
- end
- end
- lpo1()
- end;
- };
- ["Programs"] = {
- ["User programs"] = function()
- local plist = fs.list(cfile.."/Programs/User")
- table.insert(plist, 1, "..")
- local ut = ch("Choose a program to execute", plist)
- if ut ~= 1 then
- shell.run(cfile.."/Programs/User/"..plist[ut-1])
- end
- end;
- ["System programs"] = function()
- local plist = fs.list(cfile.."/Programs/System")
- table.insert(plist, 1, "..")
- local ut = ch("Choose a program to execute", plist)
- if ut ~= 1 then
- shell.run(cfile.."/Programs/System/"..plist[ut], textutils.serialize(config))
- term.setCursorBlink(false)
- end
- end;
- };
- }
- local cind = "Main"
- local ctbl1 = chy
- while true do
- if tob == true then
- clear()
- break
- end
- local ctbl = {".."}
- for i,v in pairs(ctbl1) do
- table.insert(ctbl, i)
- end
- local fl = ch(cind, ctbl)
- local tp = "nil"
- local tf = nil
- local ond = 1
- for i,v in pairs(ctbl1) do
- ond = ond + 1
- if fl == ond then
- tp = type(v)
- tf = v
- end
- end
- if tp == "function" then
- tf()
- elseif fl ~= 1 then
- local ond = 1
- for i,v in pairs(ctbl1) do
- ond = ond + 1
- if fl == ond then
- ctbl1 = v
- cind = cind.."/"..i
- end
- end
- else
- local lind = sep(cind, "/")
- local newc = "Main"
- table.remove(lind, 1)
- for i,v in pairs(lind) do
- if i ~= #lind then
- newc = newc.."/"..v
- end
- end
- table.remove(lind, #lind)
- ctbl1 = chy
- for i,v in pairs(lind) do
- ctbl1 = ctbl1[v]
- end
- cind = newc
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement