Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Autos
- Official Installer
- ]]--
- -- Files to download
- local tFiles = {
- [1] = { c = "P8eS7wLr", t = "/startup" },
- [2] = { c = "xpgTi8rg", t = "/System/.osfiles/osparts/desktop" },
- [3] = { c = "ZQ71nxhn", t = "/System/.osfiles/resources/APIs/autos" },
- [4] = { c = "LVtcJbNe", t = "/System/.osfiles/resources/APIs/settings" },
- [5] = { c = "5AFEKqJA", t = "/System/changelog" },
- [6] = { c = "G8fpURBG", t = "/System/credits" },
- [7] = { c = "b2wATXFv", t = "/System/.osfiles/resources/IMGs/fileIcon1.img" },
- [8] = { c = "aXcyP6fV", t = "/System/.osfiles/resources/IMGs/fileIcon2.img" },
- [9] = { c = "kUE4WXk1", t = "/System/.osfiles/resources/IMGs/fileBack1.img" },
- [10] = { c = "8EFQPB2p", t = "/System/.osfiles/resources/IMGs/fileSplash.img" }
- }
- -- The colors of the GUI
- local col_mainback = 8
- local col_maintext = 1
- local col_butnhilb = 16
- local col_butnhilt = 32768
- local col_butnback = 2048
- local col_butntext = 1
- local col_titlback = 2048
- local col_titlhilb = 8192
- local col_titlhilt = 1
- -- Current version
- local version = "0.01"
- -- The size of the terminal
- local w,h = term.getSize()
- -- The selected item (for menu)
- local selectedItem = 1
- -- Detects if in main menu or not
- local inMainMenu = true
- -- Detects if installing
- local installing = false
- -- Detects if uninstalling
- local uninstalling = false
- -- Detects if in apps menu or not
- local appsMenu = false
- -- The table for what to do when uninstalling
- uninstallFiles = {
- "fs.delete('/System')",
- "fs.delete('/startup')",
- "print('Autos has been removed.')"
- }
- -- Function that prints things to the middle of the screen (EXACTLY, NOT 1 BEHIND)
- function cPrint(t)
- local x,y = term.getCursorPos()
- local x = math.max(math.floor((w/2) - (#t / 2)), y)
- term.setCursorPos(x+1,y)
- print(t)
- end
- -- Function that writes things to the middle of the screen (EXACTLY, NOT 1 BEHIND)
- function cWrite(t)
- local x,y = term.getCursorPos()
- local x = math.max(math.floor((w/2) - (#t / 2)), y)
- term.setCursorPos(x+1,y)
- write(t)
- end
- -- Draws the background and title bar
- function draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(col_titlback)
- term.clearLine()
- term.setTextColor(col_titlhilt)
- term.setBackgroundColor(col_titlhilb)
- cPrint("[ Autos "..version.." Installer ]")
- cPrint("")
- cPrint("")
- end
- -- Draws the download
- function draw_downloadtitle()
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- term.setCursorPos(2,4)
- print("Downloading: ")
- end
- -- Sets the background
- function autosBack()
- appsMenu = false
- installing = false
- downloadApp = false
- removeApp = false
- inMainMenu = true
- selectedItem = 1
- end
- -- Install autos
- function autosInstall()
- installing = true
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- term.setCursorPos(2,4)
- cPrint("Creating directories...")
- fs.makeDir("/System")
- fs.makeDir("/System/.osfiles/")
- fs.makeDir("/System/.osfiles/resources")
- fs.makeDir("/System/.osfiles/applications")
- fs.makeDir("/System/.osfiles/osparts")
- fs.makeDir("/System/.osfiles/users")
- fs.makeDir("/System/.osfiles/resources/APIs")
- fs.makeDir("/System/.osfiles/resources/IMGs")
- sleep(0.1)
- for i=1, #tFiles do
- draw_downloadtitle()
- term.setCursorPos(2,5)
- term.setTextColor(colors.gray)
- print(tFiles[i].t)
- sFile = http.get("http://pastebin.com/raw.php?i="..tFiles[i].c)
- local contents = sFile.readAll()
- sFile.close()
- local file = fs.open(tFiles[i].t,"w")
- file.write(contents)
- file.close()
- end
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("Complete. Rebooting...")
- sleep(0.5)
- os.reboot()
- end
- -- Uninstall autos
- function autosUninstall()
- uninstalling = true
- while uninstalling do
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("Setting up uninstaller...")
- local file = fs.open("/startup","w")
- for i=1,#uninstallFiles do
- file.writeLine(uninstallFiles[i])
- end
- file.close()
- sleep(1)
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("Rebooting...")
- sleep(1)
- os.reboot()
- end
- end
- -- Downloads app function
- function autosDownloads()
- appsMenu = true
- selectedItem = 1
- while appsMenu do
- draw_maingui()
- term.setBackgroundColor(col_butnback)
- term.setTextColor(col_butntext)
- cPrint(" [ App Menu ] ")
- cPrint(" ")
- printMenu(downloadsMenu)
- term.setBackgroundColor(col_butnback)
- cPrint(" ")
- local event,key = os.pullEvent("key")
- oKeyPressed(key,downloadsMenu)
- end
- end
- -- Exit menu function
- function autosExit()
- inMainMenu = false
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- -- Download app function
- function autosDownloadApp()
- downloadApp = true
- while downloadApp do
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- term.setCursorPos(2,4)
- write("Pastebin ID: ")
- local code = read()
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- term.setCursorPos(2,4)
- write("App name: ")
- local name = read()
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("Downloading app...")
- if not fs.exists("/System/.osfiles/applications/"..name) then
- local httpCode = http.get("http://pastebin.com/raw.php?i="..e(code))
- local contents = httpCode.readAll()
- local file = assert(fs.open("/System/.osfiles/applications/"..name,"w"))
- file.write(contents)
- file.close()
- sleep(1)
- cPrint("Complete!")
- autosBack()
- else
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("App already found!")
- sleep(1)
- autosBack()
- end
- downloadApp = false
- end
- end
- -- Remove app function
- function autosRemoveApp()
- removeApp = true
- while removeApp do
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(2,4)
- write("App name: ")
- local name = read()
- if fs.exists("/System/.osfiles/applications/"..name) then
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- fs.delete("/System/.osfiles/applications/"..name)
- cPrint("Removed!")
- sleep(1)
- autosBack()
- else
- draw_maingui()
- term.setBackgroundColor(col_mainback)
- term.setTextColor(col_maintext)
- cPrint("App doesn't exist!")
- sleep(1)
- autosBack()
- end
- end
- end
- mainMenu = {
- [1] = { text = "Install ", handler = autosInstall },
- [2] = { text = "Uninstall", handler = autosUninstall },
- [3] = { text = "Downloads", handler = autosDownloads },
- [4] = { text = "Quit ", handler = autosExit }
- }
- downloadsMenu = {
- [1] = { text = "Download App", handler = autosDownloadApp },
- [2] = { text = "Remove App ", handler = autosRemoveApp },
- [3] = { text = "Back ", handler = autosBack }
- }
- -- Prints menus
- function printMenu( menu )
- for i=1,#menu do
- if i == selectedItem then
- term.setBackgroundColor(col_butnhilb)
- term.setTextColor(col_butnhilt)
- cPrint(" "..menu[i].text.." ")
- else
- term.setBackgroundColor(col_butnback)
- term.setTextColor(col_butntext)
- cPrint(" "..menu[i].text.." ")
- end
- end
- end
- -- A handler for a key pressed in a menu
- function oKeyPressed(key,menu)
- if key == keys.enter then
- oItemSelected(menu)
- elseif key == keys.up then
- if selectedItem >= 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == keys.down then
- if selectedItem <= #menu then
- selectedItem = selectedItem + 1
- end
- end
- end
- -- A handler for the selected item in a menu
- function oItemSelected(menu)
- menu[selectedItem].handler()
- end
- function main()
- while inMainMenu do
- draw_maingui()
- term.setBackgroundColor(col_butnback)
- term.setTextColor(col_butntext)
- cPrint(" [ Main Menu ] ")
- cPrint(" ")
- printMenu(mainMenu)
- term.setBackgroundColor(col_butnback)
- cPrint(" ")
- local event,key = os.pullEvent("key")
- oKeyPressed(key,mainMenu)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement