Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----Variables----
- names = {"t", "Menu"}
- adresses = {"5yu5bhR3", "fwGLRkYK"}
- amount = 2
- nameFile = nil
- adressFile = nil
- function showList()
- if amount == 0 then
- print("No programs installed")
- return
- end
- print("-------------------------")
- print("program list")
- print("-------------------------")
- for _,v in pairs(names) do
- print(v.." - "..adresses[_])
- end
- end
- function add(name, adress)
- print("Adding "..name.." to list at index "..amount+1)
- names[amount+1] = name
- adresses[amount+1] = adress
- amount = amount+1
- updateList()
- end
- function clearList()
- names = nil
- adresses = nil
- amount = 0
- fs.delete("names")
- fs.delete("adresses")
- fs.delete("amount")
- end
- function check(list, entry)
- for _,v in pairs(list) do
- if v == entry then
- -- print("found "..entry.."/"..v.." at ".._)
- -- sleep(3)
- return _
- end
- end
- return -1
- end
- function save(table,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function load(name)
- if not fs.exists(name) then
- print("Error! cant find file!")
- return
- end
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function updateList()
- save(names,"names")
- save(adresses, "adresses")
- save(amount, "amount")
- end
- -----------Formating-----------------
- function draw_text_term(x, y, text, text_color, bg_color)
- term.setTextColor(text_color)
- term.setBackgroundColor(bg_color)
- term.setCursorPos(x,y)
- write(text)
- end
- function draw_line_term(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line_term(x, y, length, bg_color) --background bar
- draw_line_term(x, y, barSize, bar_color) --progress so far
- end
- function menu_bars()
- -- draw_line_term(1, 1, 55, colors.white)
- -- draw_text_term(14, 1, "ComputerCraft Test Program", colors.black, colors.white)
- -- draw_line_term(1, 19, 55, colors.white)
- -- draw_text_term(20, 19, "", colors.black, colors.black)
- end
- --------------Installer---------------------
- function install(program, pastebin)
- term.clear()
- menu_bars()
- draw_text_term(1, 4, "Installing: "..program.."", colors.white, colors.black)
- term.setCursorPos(1,6)
- term.setTextColor(colors.white)
- sleep(0.5)
- --delete any old backups
- if fs.exists(program.."_old") then
- fs.delete(program.."_old")
- end
- --remove old configs
- if fs.exists("config.txt") then
- fs.delete("config.txt")
- end
- --backup current program
- if fs.exists(program) then
- fs.copy(program, program.."_old")
- fs.delete(program)
- end
- --remove program and fetch new copy
- shell.run("pastebin get "..pastebin.." "..program)
- sleep(0.5)
- end
- ----------Main-------------
- args = {...}
- print(args[1])
- print(args[2])
- print(args[3])
- --initializing tables
- if (fs.exists("names") and fs.exists("adresses") and fs.exists("amount")) then
- names = load("names")
- adresses = load("adresses")
- amount = load("amount")
- end
- --sleep(1)
- if amount > 0 then
- nCheck = check(names, args[1])
- --print("nCheck = "..nCheck)
- else
- nCheck = -1
- end
- if args[1] == "showList" then
- showList()
- return
- end
- if args[1] == "init" then
- for _,v in pairs(names) do
- install(v, adresses[_])
- end
- updateList()
- error()
- end
- if args[1] == "clear" then
- clearList()
- error()
- end
- if args[1] == "showItem" then
- print(names[arg[2]].." - "..adresses[arg[2]])
- error()
- end
- if args[1] == "addAmount" then
- amount = amount + args[2]
- error()
- end
- if args[1] == "amount" then
- print("Amounts of programs: "..amount)
- error()
- end
- if (nCheck > -1 and args[2] == nil) then
- install(args[1], adresses[nCheck])
- error()
- end
- if (nCheck > -1 and args[2] ~= adresses[nCheck]) then
- adresses[nCheck] = args[2]
- install(args[1], args[2])
- updateList()
- error()
- end
- if (nCheck == -1 and args[2] == nil) then
- term.setTextColor(colors.red)
- print("Name is not in the list. Adding a new program requires pastebin adress")
- term.setTextColor(colors.white)
- error()
- end
- if (nCheck == -1 and args[2]) then
- add(args[1], args[2])
- install(args[1], args[2])
- error()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement