Advertisement
AquaJD

[AUT] Installer

May 4th, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.35 KB | None | 0 0
  1. --[[
  2.  
  3.     Autos
  4.     Official Installer
  5.  
  6. ]]--
  7.  
  8. -- Files to download
  9. local tFiles = {
  10.     [1] = { c = "P8eS7wLr", t = "/startup" },
  11.     [2] = { c = "xpgTi8rg", t = "/System/.osfiles/osparts/desktop" },
  12.     [3] = { c = "ZQ71nxhn", t = "/System/.osfiles/resources/APIs/autos" },
  13.     [4] = { c = "LVtcJbNe", t = "/System/.osfiles/resources/APIs/settings" },
  14.     [5] = { c = "5AFEKqJA", t = "/System/changelog" },
  15.     [6] = { c = "G8fpURBG", t = "/System/credits" },
  16.     [7] = { c = "b2wATXFv", t = "/System/.osfiles/resources/IMGs/fileIcon1.img" },
  17.     [8] = { c = "aXcyP6fV", t = "/System/.osfiles/resources/IMGs/fileIcon2.img" },
  18.     [9] = { c = "kUE4WXk1", t = "/System/.osfiles/resources/IMGs/fileBack1.img" },
  19.     [10] = { c = "8EFQPB2p", t = "/System/.osfiles/resources/IMGs/fileSplash.img" }
  20. }
  21.  
  22. -- The colors of the GUI
  23. local col_mainback = 8
  24. local col_maintext = 1
  25. local col_butnhilb = 16
  26. local col_butnhilt = 32768
  27. local col_butnback = 2048
  28. local col_butntext = 1
  29. local col_titlback = 2048
  30. local col_titlhilb = 8192
  31. local col_titlhilt = 1
  32.  
  33. -- Current version
  34. local version = "0.01"
  35. -- The size of the terminal
  36. local w,h = term.getSize()
  37. -- The selected item (for menu)
  38. local selectedItem = 1
  39. -- Detects if in main menu or not
  40. local inMainMenu = true
  41. -- Detects if installing
  42. local installing = false
  43. -- Detects if uninstalling
  44. local uninstalling = false
  45. -- Detects if in apps menu or not
  46. local appsMenu = false
  47. -- The table for what to do when uninstalling
  48. uninstallFiles = {
  49.     "fs.delete('/System')",
  50.     "fs.delete('/startup')",
  51.     "print('Autos has been removed.')"
  52. }
  53.  
  54. -- Function that prints things to the middle of the screen (EXACTLY, NOT 1 BEHIND)
  55. function cPrint(t)
  56.     local x,y = term.getCursorPos()
  57.     local x = math.max(math.floor((w/2) - (#t / 2)), y)
  58.     term.setCursorPos(x+1,y)
  59.     print(t)
  60. end
  61. -- Function that writes things to the middle of the screen (EXACTLY, NOT 1 BEHIND)
  62. function cWrite(t)
  63.     local x,y = term.getCursorPos()
  64.     local x = math.max(math.floor((w/2) - (#t / 2)), y)
  65.     term.setCursorPos(x+1,y)
  66.     write(t)
  67. end
  68.  
  69. -- Draws the background and title bar
  70. function draw_maingui()
  71.     term.setBackgroundColor(col_mainback)
  72.     term.clear()
  73.     term.setCursorPos(1,1)
  74.     term.setBackgroundColor(col_titlback)
  75.     term.clearLine()
  76.     term.setTextColor(col_titlhilt)
  77.     term.setBackgroundColor(col_titlhilb)
  78.     cPrint("[ Autos "..version.." Installer ]")
  79.     cPrint("")
  80.     cPrint("")
  81. end
  82.  
  83. -- Draws the download
  84. function draw_downloadtitle()
  85.     draw_maingui()
  86.     term.setBackgroundColor(col_mainback)
  87.     term.setTextColor(col_maintext)
  88.     term.setCursorPos(2,4)
  89.     print("Downloading: ")
  90. end
  91.  
  92. -- Sets the background
  93. function autosBack()
  94.     appsMenu = false
  95.     installing = false
  96.     downloadApp = false
  97.     removeApp = false
  98.     inMainMenu = true
  99.     selectedItem = 1
  100. end
  101.  
  102. -- Install autos
  103. function autosInstall()
  104.     installing = true
  105.     draw_maingui()
  106.     term.setBackgroundColor(col_mainback)
  107.     term.setTextColor(col_maintext)
  108.     term.setCursorPos(2,4)
  109.     cPrint("Creating directories...")
  110.     fs.makeDir("/System")
  111.     fs.makeDir("/System/.osfiles/")
  112.     fs.makeDir("/System/.osfiles/resources")
  113.     fs.makeDir("/System/.osfiles/applications")
  114.     fs.makeDir("/System/.osfiles/osparts")
  115.     fs.makeDir("/System/.osfiles/users")
  116.     fs.makeDir("/System/.osfiles/resources/APIs")
  117.     fs.makeDir("/System/.osfiles/resources/IMGs")
  118.     sleep(0.1)
  119.     for i=1, #tFiles do
  120.         draw_downloadtitle()
  121.         term.setCursorPos(2,5)
  122.         term.setTextColor(colors.gray)
  123.         print(tFiles[i].t)
  124.         sFile = http.get("http://pastebin.com/raw.php?i="..tFiles[i].c)
  125.         local contents = sFile.readAll()
  126.         sFile.close()
  127.         local file = fs.open(tFiles[i].t,"w")
  128.         file.write(contents)
  129.         file.close()
  130.     end
  131.     draw_maingui()
  132.     term.setBackgroundColor(col_mainback)
  133.     term.setTextColor(col_maintext)
  134.     cPrint("Complete. Rebooting...")
  135.     sleep(0.5)
  136.     os.reboot()
  137. end
  138.  
  139. -- Uninstall autos
  140. function autosUninstall()
  141.     uninstalling = true
  142.     while uninstalling do
  143.         draw_maingui()
  144.         term.setBackgroundColor(col_mainback)
  145.         term.setTextColor(col_maintext)
  146.         cPrint("Setting up uninstaller...")
  147.         local file = fs.open("/startup","w")
  148.         for i=1,#uninstallFiles do
  149.             file.writeLine(uninstallFiles[i])
  150.         end
  151.         file.close()
  152.         sleep(1)
  153.         draw_maingui()
  154.         term.setBackgroundColor(col_mainback)
  155.         term.setTextColor(col_maintext)
  156.         cPrint("Rebooting...")
  157.         sleep(1)
  158.         os.reboot()
  159.     end
  160. end
  161.  
  162. -- Downloads app function
  163. function autosDownloads()
  164.     appsMenu = true
  165.     selectedItem = 1
  166.     while appsMenu do
  167.         draw_maingui()
  168.         term.setBackgroundColor(col_butnback)
  169.         term.setTextColor(col_butntext)
  170.         cPrint("    [ App Menu ]    ")
  171.         cPrint("                    ")
  172.         printMenu(downloadsMenu)
  173.         term.setBackgroundColor(col_butnback)
  174.         cPrint("                    ")
  175.         local event,key = os.pullEvent("key")
  176.         oKeyPressed(key,downloadsMenu)
  177.     end
  178. end
  179.  
  180. -- Exit menu function
  181. function autosExit()
  182.     inMainMenu = false
  183.     term.setBackgroundColor(colors.black)
  184.     term.clear()
  185.     term.setCursorPos(1,1)
  186. end
  187.  
  188. -- Download app function
  189. function autosDownloadApp()
  190.     downloadApp = true
  191.     while downloadApp do
  192.         draw_maingui()
  193.         term.setBackgroundColor(col_mainback)
  194.         term.setTextColor(col_maintext)
  195.         term.setCursorPos(2,4)
  196.         write("Pastebin ID: ")
  197.         local code = read()
  198.         draw_maingui()
  199.         term.setBackgroundColor(col_mainback)
  200.         term.setTextColor(col_maintext)
  201.         term.setCursorPos(2,4)
  202.         write("App name: ")
  203.         local name = read()
  204.         draw_maingui()
  205.         term.setBackgroundColor(col_mainback)
  206.         term.setTextColor(col_maintext)
  207.         cPrint("Downloading app...")
  208.         if not fs.exists("/System/.osfiles/applications/"..name) then
  209.             local httpCode = http.get("http://pastebin.com/raw.php?i="..e(code))
  210.             local contents = httpCode.readAll()
  211.             local file = assert(fs.open("/System/.osfiles/applications/"..name,"w"))
  212.             file.write(contents)
  213.             file.close()
  214.             sleep(1)
  215.             cPrint("Complete!")
  216.             autosBack()
  217.         else
  218.             draw_maingui()
  219.             term.setBackgroundColor(col_mainback)
  220.             term.setTextColor(col_maintext)
  221.             cPrint("App already found!")
  222.             sleep(1)
  223.             autosBack()
  224.         end
  225.         downloadApp = false
  226.     end
  227. end
  228.  
  229. -- Remove app function
  230. function autosRemoveApp()
  231.     removeApp = true
  232.     while removeApp do
  233.         drawTitle()
  234.         term.setBackgroundColor(colors.white)
  235.         term.setTextColor(colors.black)
  236.         term.setCursorPos(2,4)
  237.         write("App name:  ")
  238.         local name = read()
  239.         if fs.exists("/System/.osfiles/applications/"..name) then
  240.             draw_maingui()
  241.             term.setBackgroundColor(col_mainback)
  242.             term.setTextColor(col_maintext)
  243.             fs.delete("/System/.osfiles/applications/"..name)
  244.             cPrint("Removed!")
  245.             sleep(1)
  246.             autosBack()
  247.         else
  248.             draw_maingui()
  249.             term.setBackgroundColor(col_mainback)
  250.             term.setTextColor(col_maintext)
  251.             cPrint("App doesn't exist!")
  252.             sleep(1)
  253.             autosBack()
  254.         end
  255.     end
  256. end
  257.  
  258. mainMenu = {
  259.     [1] = { text = "Install  ", handler = autosInstall },
  260.     [2] = { text = "Uninstall", handler = autosUninstall },
  261.     [3] = { text = "Downloads", handler = autosDownloads },
  262.     [4] = { text = "Quit     ", handler = autosExit }
  263. }
  264.  
  265. downloadsMenu = {
  266.     [1] = { text = "Download App", handler = autosDownloadApp },
  267.     [2] = { text = "Remove App  ", handler = autosRemoveApp },
  268.     [3] = { text = "Back        ", handler = autosBack }
  269. }
  270.  
  271. -- Prints menus
  272. function printMenu( menu )
  273.   for i=1,#menu do
  274.     if i == selectedItem then
  275.       term.setBackgroundColor(col_butnhilb)
  276.       term.setTextColor(col_butnhilt)
  277.       cPrint("    "..menu[i].text.."    ")
  278.     else
  279.       term.setBackgroundColor(col_butnback)
  280.       term.setTextColor(col_butntext)
  281.       cPrint("    "..menu[i].text.."    ")
  282.     end
  283.   end
  284. end
  285.  
  286. -- A handler for a key pressed in a menu
  287. function oKeyPressed(key,menu)
  288.     if key == keys.enter then
  289.         oItemSelected(menu)
  290.     elseif key == keys.up then
  291.         if selectedItem >= 1 then
  292.             selectedItem = selectedItem - 1
  293.         end
  294.     elseif key == keys.down then
  295.         if selectedItem <= #menu then
  296.             selectedItem = selectedItem + 1
  297.         end
  298.     end
  299. end
  300.  
  301. -- A handler for the selected item in a menu
  302. function oItemSelected(menu)
  303.     menu[selectedItem].handler()
  304. end
  305.  
  306. function main()
  307.     while inMainMenu do
  308.         draw_maingui()
  309.         term.setBackgroundColor(col_butnback)
  310.         term.setTextColor(col_butntext)
  311.         cPrint("  [ Main Menu ]  ")
  312.         cPrint("                 ")
  313.         printMenu(mainMenu)
  314.         term.setBackgroundColor(col_butnback)
  315.         cPrint("                 ")
  316.         local event,key = os.pullEvent("key")
  317.         oKeyPressed(key,mainMenu)
  318.     end
  319. end
  320.  
  321. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement