Advertisement
RabaGhast

Updater

Oct 1st, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. ----Variables----
  2. names = {"GUI", "Menu"}
  3. adresses = {"XVuSA68R", "fwGLRkYK"}
  4. amount = 2
  5.  
  6. function showList()
  7.   print("-------------------------")
  8.   print("program list")
  9.   print("-------------------------")
  10.    for _,v in pairs(names) do
  11.      print(v.." - "..adresses[_])
  12.   end
  13. end
  14.  
  15. function add(name, adress)
  16.   names[amount+1] = name
  17.   adresses[amount+1] = adress
  18.   amount = amount+1
  19. end
  20.  
  21. function check(list, entry)
  22.   for _,v in pairs(list) do
  23.     if v == entry then
  24.      -- print("found "..entry.."/"..v.." at ".._)
  25.      -- sleep(3)
  26.       return _
  27.     end
  28.   end
  29.   return -1
  30. end
  31.  
  32. -----------Formating-----------------
  33.  
  34. function draw_text_term(x, y, text, text_color, bg_color)
  35.   term.setTextColor(text_color)
  36.   term.setBackgroundColor(bg_color)
  37.   term.setCursorPos(x,y)
  38.   write(text)
  39. end
  40.  
  41. function draw_line_term(x, y, length, color)
  42.     term.setBackgroundColor(color)
  43.     term.setCursorPos(x,y)
  44.     term.write(string.rep(" ", length))
  45. end
  46.  
  47. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  48.   local barSize = math.floor((minVal/maxVal) * length)
  49.  
  50.   draw_line_term(x, y, length, bg_color) --background bar
  51.   draw_line_term(x, y, barSize, bar_color)  --progress so far
  52. end
  53.  
  54. function menu_bars()
  55.  -- draw_line_term(1, 1, 55, colors.white)
  56.  -- draw_text_term(14, 1, "ComputerCraft Test Program", colors.black, colors.white)
  57.  
  58.  -- draw_line_term(1, 19, 55, colors.white)
  59.  -- draw_text_term(20, 19, "", colors.black, colors.black)
  60. end
  61.  
  62. --------------Installer---------------------
  63.  
  64. function install(program, pastebin)
  65.   term.clear()
  66.   menu_bars()
  67.  
  68.   draw_text_term(1, 4, "Installing: "..program.."", colors.white, colors.black)
  69.   term.setCursorPos(1,6)
  70.   term.setTextColor(colors.white)
  71.   sleep(0.5)
  72.  
  73.   --delete any old backups
  74.   if fs.exists(program.."_old") then
  75.     fs.delete(program.."_old")
  76.     end
  77.  
  78.   --remove old configs
  79.   if fs.exists("config.txt") then
  80.     fs.delete("config.txt")
  81.     end
  82.  
  83.   --backup current program
  84.   if fs.exists(program) then
  85.     fs.copy(program, program.."_old")
  86.     fs.delete(program)
  87.     end
  88.  
  89.   --remove program and fetch new copy
  90.   shell.run("pastebin get "..pastebin.." "..program)
  91.  
  92.   sleep(0.5)
  93.  
  94. end
  95.  
  96. ----------Main-------------
  97.  
  98. args = {...}
  99. print(args[1])
  100. print(args[2])
  101. print(args[3])
  102.  
  103. --sleep(1)
  104.  
  105. nCheck = check(names, args[1])
  106. --print("nCheck = "..nCheck)
  107.  
  108. if args[1] == "showList" then
  109.   showList()
  110.   return
  111. end
  112.  
  113. if args[1] == "init" then
  114.   for _,v in pairs(names) do
  115.     install(v, adresses[_])
  116.   end
  117.   error()
  118. end
  119.  
  120. if args[1] == "showItem" then
  121.   print(names[arg[2]].." - "..adresses[arg[2]])
  122.   error()
  123. end
  124.  
  125. if args[1] == "addAmount" then
  126.   amount = amount + args[2]
  127.   error()
  128. end
  129.  
  130. if args[1] == "amount" then
  131.   print("Amounts of programs: "..amount)
  132.   error()
  133. end
  134.  
  135. if (nCheck > -1 and args[2] == nil) then
  136.   install(args[1], adresses[nCheck])
  137.   error()
  138. end
  139.  
  140. if (nCheck > -1 and args[2] ~= adresses[nCheck]) then
  141.   adresses[nCheck] = args[2]
  142.   install(args[1], args[2])
  143.   error()
  144. end
  145.  
  146. if (nCheck == -1 and args[2] == nil) then
  147.   term.setTextColor(colors.red)
  148.   print("Name is not in the list. Adding a new program requires pastebin adress")
  149.   term.setTextColor(colors.white)
  150.   error()
  151. end
  152.  
  153. if (nCheck == -1 and args[2]) then
  154.   add(args[1], args[2])
  155.   install(args[1], args[2])
  156.   error()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement