Advertisement
sanovskiy

KubachOs launcher

Nov 16th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. function Clear()
  2.  term.clear()
  3.  term.setCursorPos(1,1)
  4. end
  5.  
  6. function drawLogo()
  7.   term.setBackgroundColor(colors.white)
  8.   term.setTextColor(colors.blue)
  9.   term.clear()
  10.   term.setCursorPos(1,7)
  11.   -- print("    _  __     _                _        ____   _____ ")
  12.   -- print("   | |/ /    | |              | |      / __ \\ / ____|")
  13.   -- print("   | ' /_   _| |__   __ _  ___| |__   | |  | | (___  ")
  14.   -- print("   |  <| | | | '_ \\ / _' |/ __| '_ \\  | |  | |\\___ \\ ")
  15.   -- print("   | . \\ |_| | |_) | (_| | (__| | | | | |__| |____) |")
  16.   -- print("   |_|\\_\\__,_|_.__/ \\__,_|\\___|_| |_|  \\____/|_____/ ")
  17.   print("     __ __     __            __     ____  ____")
  18.   print("    / // /_ __/ /  ___ _____/ /    / __ \\/ __/")
  19.   print("   / ,< / // / _ \\/ _ '/ __/ _ \\  / /_/ /\\ \\  ")
  20.   print("  /_/|_|\\_,_/_.__/\\_,_/\\__/_//_/  \\____/___/  ")
  21.   cycle={"-","\\","|","/"}
  22.   for i=1,60 do
  23.     term.setCursorPos(22,12)
  24.     cur = i%4+1
  25.     print("Loading " .. cycle[cur])
  26.     sleep(0.05)
  27.   end
  28.   -- sleep(3)
  29.                                                                                      
  30.                                                                                      
  31.  
  32. end
  33. drawLogo()
  34. -- kubachwrpper
  35. Menu = {}
  36. if fs.exists("mcwarp") then
  37.   table.insert(Menu,{Name="Let's warp to space!",Command="mcwarp"})
  38. end
  39. if fs.exists("mineos2") then
  40.   table.insert(Menu,{Name="Wanna diamonds?",Command="mineos2"})
  41. elseif fs.exists("mineos1") then
  42.   table.insert(Menu,{Name="Wanna diamonds?",Command="mineos1"})
  43. end
  44. table.insert(Menu,{Name="Update",Command="san update launcher"})
  45. table.insert(Menu,{Name="Reboot",Command="reboot"})
  46.  
  47. currentMenuChoice=1
  48. configFile = "launcher.conf"
  49. shell.run("rm","startup")
  50. sfile= fs.open("startup", "w") or error("Cannot open file reactor.conf", 2)
  51. sfile.write("shell.run(\"launcher\")")
  52. sfile.close()
  53.  
  54. local function saveConfig(table, file)
  55.   local fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
  56.   fConfig.write(textutils.serialize(table))
  57.   fConfig.close()
  58. end
  59. local function loadConfig(file)
  60.   local fConfig = fs.open(file, "r")
  61.   local ret = textutils.unserialize(fConfig.readAll())
  62.   fConfig.close()
  63.   return ret
  64. end
  65. if fs.exists(configFile) then
  66.   cfg=loadConfig(configFile)
  67. else
  68.   cfg={}
  69.   cfg["startup"] = nil
  70.   saveConfig(cfg, configFile)
  71. end
  72. if cfg["startup"]~=nil and cfg["startup"]~="reboot" then
  73.   shell.run(cfg["startup"])
  74. end
  75.  
  76. function Clear()
  77.  term.clear()
  78.  term.setCursorPos(1,1)
  79. end
  80. function drawButton(cX,cY,Text,color,bgcolor,inverted)
  81.   inverted = inverted or false
  82.   term.setCursorPos(cX,cY)
  83.   if not(inverted) then
  84.     term.setBackgroundColor(bgcolor)
  85.     term.setTextColor(color)
  86.   else
  87.     term.setBackgroundColor(color)
  88.     term.setTextColor(bgcolor)
  89.   end
  90.   term.write("+"..string.rep("-", string.len(Text)+2).."+")
  91.   term.setCursorPos(cX,cY+1)
  92.   term.write("+ "..Text.." +")
  93.   term.setCursorPos(cX,cY+2)
  94.   term.write("+"..string.rep("-", string.len(Text)+2).."+")
  95. end
  96.  
  97. function drawMenu()
  98.   term.setBackgroundColor(colors.blue)
  99.   Clear()
  100.   local termW, termH = term.getSize()
  101.   local summButtSize = (#Menu*3) + (#Menu-1)
  102.   cY = math.floor((termH-summButtSize)/2)
  103.   maxButtonWidth = 0
  104.   for i=1,#Menu do
  105.      if maxButtonWidth<string.len(Menu[i]["Name"]) then
  106.        maxButtonWidth = string.len(Menu[i]["Name"])
  107.      end
  108.   end
  109.   cX = math.floor((termW-(maxButtonWidth+4))/2)
  110.   for i=1,#Menu do
  111.     inverted = false
  112.     if i==currentMenuChoice then
  113.       inverted = true
  114.     end
  115.     local lChop = math.floor((maxButtonWidth-string.len(Menu[i]["Name"]))/2)
  116.     local rChop = maxButtonWidth - string.len(Menu[i]["Name"]) - lChop
  117.     if lChop<0 then
  118.       lChop=0
  119.     end
  120.     if rChop<0 then
  121.       rChop=0
  122.     end
  123.     drawButton(cX,cY,string.rep(" ",lChop)..Menu[i]["Name"]..string.rep(" ",rChop),colors.black,colors.white,inverted)
  124.     cY=cY+4
  125.   end
  126. end
  127.  
  128. while true do
  129.   drawMenu()
  130.   local event, keycode = os.pullEvent("key")
  131.   if keycode == 200 then
  132.     if currentMenuChoice==1 then
  133.       currentMenuChoice=#Menu
  134.     else
  135.       currentMenuChoice=currentMenuChoice-1
  136.     end
  137.   elseif keycode == 208 or keycode==15 then  
  138.     if currentMenuChoice==#Menu then
  139.       currentMenuChoice=1
  140.     else
  141.       currentMenuChoice=currentMenuChoice+1
  142.     end
  143.   elseif keycode == 57 or keycode == 28 then
  144.     Clear()
  145.     cfg["startup"] = Menu[currentMenuChoice]["Command"]
  146.     saveConfig(cfg, configFile)
  147.     shell.run(Menu[currentMenuChoice]["Command"])
  148.     cfg["startup"] = nil
  149.     saveConfig(cfg, configFile)
  150.   end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement