Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Local Variables and Tables ]]--
- local tFiles = {
- textutils.urlEncode("HNJqf0AD"), -- main
- textutils.urlEncode("RWjQFdZX"), -- startup
- textutils.urlEncode("j1s4LwJ9"), -- readme
- textutils.urlEncode("3iFFqppT"), -- icon 1
- textutils.urlEncode("vyAZc6tJ"), -- luaide
- textutils.urlEncode("PARriC6j"), -- icon fm
- textutils.urlEncode("uGWi9Vwa"), -- splash
- textutils.urlEncode("jUjT10uK"), -- login layout
- textutils.urlEncode("SaqqWwWW"), -- main bg
- textutils.urlEncode("RkkQTA9j"), -- main bg 2
- textutils.urlEncode("pnzdr8FB"), -- file manager
- textutils.urlEncode("udDhEHeV"), -- npaintpro
- textutils.urlEncode("Ur9tN2Ct"), -- quicktils API
- textutils.urlEncode("LVtcJbNe"), -- settings API
- textutils.urlEncode("pK5YmEkg"), -- controlpanel
- textutils.urlEncode("byczahQr") -- about
- }
- local w,h = term.getSize()
- local selectedItem = 1
- local inMainMenu = true
- local installing = false
- local uninstalling = false
- local appsMenu = false
- startFiles = {
- "fs.delete('/AquaOS')",
- "fs.delete('/startup')",
- "print('Successfully removed!')"
- }
- --[[ Utility Functions ]]--
- function centerPrint(t)
- local x,y = term.getCursorPos()
- x = math.max(math.floor((w / 2) - (#t / 2)), y)
- term.setCursorPos(x+1,y)
- print(t)
- end
- function centerWrite(t)
- local x,y = term.getCursorPos()
- x = math.max(math.floor((w / 2) - (#t / 2)), y)
- term.setCursorPos(x+1,y)
- write(t)
- end
- function drawTitle()
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- term.clearLine()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- centerPrint("[ AquaOS Updater/Installer ]")
- term.setBackgroundColor(colors.black)
- centerPrint("")
- centerPrint("")
- end
- function drawDownloadTitle()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(5,4)
- write("Downloading: ")
- end
- --[[ Menu Functions ]]--
- function aosBack()
- appsMenu = false
- installing = false
- uninstalling = false
- downloadApp = false
- removeApp = false
- inMainMenu = true
- selectedItem = 1
- end
- function aosInstall()
- installing = true
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerPrint("Creating directories...")
- fs.makeDir("/AquaOS")
- fs.makeDir("/AquaOS/Resources")
- fs.makeDir("/AquaOS/.Boot")
- fs.makeDir("/AquaOS/Resources/APIs")
- fs.makeDir("/AquaOS/Resources/Apps")
- fs.makeDir("/AquaOS/Resources/.backgrounds")
- fs.makeDir("/AquaOS/Resources/.icons")
- sleep(3)
- while installing do
- -- File 1
- drawDownloadTitle()
- write("/AquaOS/.Boot/Main")
- sFile = http.get("http://pastebin.com/raw.php?i="..tFiles[1])
- local contents = sFile.readAll()
- sFile.close()
- local file = assert(fs.open("/AquaOS/.Boot/Main","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 2
- drawDownloadTitle()
- write("../Apps/FileManager")
- fmFile = http.get("http://pastebin.com/raw.php?i="..tFiles[11])
- local contents = fmFile.readAll()
- fmFile.close()
- local file = assert(fs.open("/AquaOS/Resources/Apps/FileManager","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 3
- drawDownloadTitle()
- write("../Apps/NPaintPro")
- fsFile = http.get("http://pastebin.com/raw.php?i="..tFiles[12])
- local contents = fsFile.readAll()
- fsFile.close()
- local file = assert(fs.open("/AquaOS/Resources/Apps/NPaintPro","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 4
- drawDownloadTitle()
- write("../APIs/QuickTils")
- qtFile = http.get("http://pastebin.com/raw.php?i="..tFiles[13])
- local contents = qtFile.readAll()
- qtFile.close()
- local file = assert(fs.open("/AquaOS/Resources/APIs/QuickTils","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 5
- drawDownloadTitle()
- write("../APIs/Settings")
- flFile = http.get("http://pastebin.com/raw.php?i="..tFiles[14])
- local contents = flFile.readAll()
- flFile.close()
- local file = assert(fs.open("/AquaOS/Resources/APIs/Settings","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 6
- drawDownloadTitle()
- write("../.icons/.icon")
- ico1File = http.get("http://pastebin.com/raw.php?i="..tFiles[4])
- local contents = ico1File.readAll()
- ico1File.close()
- local file = assert(fs.open("/AquaOS/Resources/.icons/.icon","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 7
- drawDownloadTitle()
- write("../.backgrounds/.mainBG")
- mainBGFile = http.get("http://pastebin.com/raw.php?i="..tFiles[9])
- local contents = mainBGFile.readAll()
- mainBGFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.mainBG","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 8
- drawDownloadTitle()
- write("/startup")
- launchFile = http.get("http://pastebin.com/raw.php?i="..tFiles[2])
- local contents = launchFile.readAll()
- launchFile.close()
- if not fs.exists("/startup") then
- local file = assert(fs.open("/startup","w"))
- file.write(contents)
- file.close()
- else
- local file = assert(fs.open("/startup","r"))
- local oldContents = file.readAll()
- file.close()
- local file = assert(fs.open("/oldStartup","w"))
- file.write(oldContents)
- file.close()
- local file = assert(fs.open("/startup","w"))
- file.write(contents)
- file.close()
- end
- sleep(1)
- -- File 9
- drawDownloadTitle()
- write("../.backgrounds/.splash")
- splashFile = http.get("http://pastebin.com/raw.php?i="..tFiles[7])
- local contents = splashFile.readAll()
- splashFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.splash","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 10
- drawDownloadTitle()
- write("../.backgrounds/.loginLayout")
- lSplashFile = http.get("http://pastebin.com/raw.php?i="..tFiles[8])
- local contents = lSplashFile.readAll()
- lSplashFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.loginLayout","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 11
- drawDownloadTitle()
- write("../.icons/.iconFM")
- iconFMFile = http.get("http://pastebin.com/raw.php?i="..tFiles[6])
- local contents = iconFMFile.readAll()
- iconFMFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.icons/.iconFM","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 12
- drawDownloadTitle()
- write("../.backgrounds/.mainBG2")
- mainBG2File = http.get("http://pastebin.com/raw.php?i="..tFiles[10])
- local contents = mainBG2File.readAll()
- mainBG2File.close()
- local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.mainBG2","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 13
- drawDownloadTitle()
- write("../Apps/LuaIDE")
- luaFile = http.get("http://pastebin.com/raw.php?i="..tFiles[5])
- local contents = luaFile.readAll()
- luaFile.close()
- local file = assert(fs.open("/AquaOS/Resources/Apps/LuaIDE","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 14
- drawDownloadTitle()
- write("/AquaOS/readme.txt")
- readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[3])
- local contents = readFile.readAll()
- readFile.close()
- local file = assert(fs.open("/AquaOS/readme.txt","w"))
- file.write(contents)
- file.close()
- sleep(.5)
- -- File 15
- drawDownloadTitle()
- write("../Resources/.control")
- readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[15])
- local contents = readFile.readAll()
- readFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.control","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File 16
- drawDownloadTitle()
- write("../Resources/.about")
- readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[16])
- local contents = readFile.readAll()
- readFile.close()
- local file = assert(fs.open("/AquaOS/Resources/.about","w"))
- file.write(contents)
- file.close()
- sleep(1)
- -- File Finish
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- write("Complete. Rebooting...")
- sleep(2)
- os.reboot()
- end
- end
- function aosUninstall()
- uninstalling = true
- while uninstalling do
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("Please choose Apps/APIs to keep! (t/f)")
- centerWrite("")
- centerWrite("QuickTils: ")
- local fQT = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("fLib: ")
- local fFL = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("LuaIDE: ")
- local fIDE = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("NPaintPro: ")
- local fNPP = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("FileManager: ")
- local fFB = read()
- drawTitle()
- centerPrint("Removing AquaOS...")
- fs.makeDir("/AOSLeftovers")
- if fQT == "t" then
- fs.move("/AquaOS/Resources/APIs/QuickTils","/AOSLeftovers/QuickTils")
- elseif fQT == "f" then
- return false
- else
- error("Input recognisation failure.")
- end
- if fFL == "t" then
- fs.move("/AquaOS/Resources/APIs/fLib","AOSLeftovers/fLib")
- elseif fFL == "f" then
- return false
- else
- error("Input recognisation failure.")
- end
- if fIDE == "t" then
- fs.move("/AquaOS/Resources/Apps/LuaIDE","AOSLeftovers/LuaIDE")
- elseif fIDE == "f" then
- return false
- else
- error("Input recognisation failure.")
- end
- if fNPP == "t" then
- fs.move("/AquaOS/Resources/Apps/NPaintPro","AOSLeftovers/NPaintPro")
- elseif fNPP == "f" then
- return false
- else
- error("Input recognisation failure.")
- end
- if fFB == "t" then
- fs.move("/AquaOS/Resources/Apps/FileManager","AOSLeftovers/FileManager")
- elseif fFB == "f" then
- return false
- else
- error("Input recognisation failure.")
- end
- local file = fs.open("/startup","w")
- for i=1,#startFiles do
- file.writeLine(startFiles[i])
- end
- sleep(2)
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerPrint("Rebooting..")
- sleep(2)
- uninstalling = false
- os.reboot()
- end
- end
- function aosDownloads()
- appsMenu = true
- selectedItem = 1
- while appsMenu do
- drawTitle()
- term.setBackgroundColor(colors.blue)
- centerPrint(" [ App Menu ] ")
- centerPrint(" ")
- printMenu(downloadsMenu)
- term.setBackgroundColor(colors.blue)
- centerPrint(" ")
- local event, key = os.pullEvent("key")
- oKeyPressed(key,downloadsMenu)
- end
- end
- function aosExit()
- inMainMenu = false
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- function aosDownloadApp()
- downloadApp = true
- while downloadApp do
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("Pastebin ID: ")
- local code = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("App name: ")
- local appName = read()
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerPrint("Downloading app...")
- if not fs.exists("/AquaOS/Apps/"..appName) then
- local httpCode = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))
- local contents = httpCode.readAll()
- local file = assert(fs.open(filename,"w"))
- file.write(contents)
- file.close()
- else
- error("File already exists!")
- end
- sleep(2)
- centerPrint("Complete! Moved file to /AquaOS/Apps/.")
- aosBack()
- end
- end
- function aosRemoveApp()
- removeApp = true
- while removeApp do
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- centerWrite("App name: ")
- local appName = read()
- if fs.exists("/AquaOS/Apps/"..appName) then
- if appName == "LuaIDE" then
- error("You cannot delete this app!")
- elseif appName == "FileManager" then
- error("You cannot delete this app!")
- elseif appName == "NPaintPro" then
- error("You cannot delete this app!")
- else
- drawTitle()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- fs.delete("/AquaOS/Resources/Apps/"..appName)
- centerPrint("Removed!")
- sleep(2)
- aosBack()
- end
- else
- error("File does not exist!")
- end
- end
- end
- --[[ Menus ]]--
- mainMenu = {
- [1] = { text = "Install ", handler = aosInstall },
- [2] = { text = "Uninstall", handler = aosUninstall },
- [3] = { text = "Downloads", handler = aosDownloads },
- [4] = { text = "Quit ", handler = aosExit }
- }
- downloadsMenu = {
- [1] = { text = "Download App", handler = aosDownloadApp },
- [2] = { text = "Remove App ", handler = aosRemoveApp },
- [3] = { text = "Back ", handler = aosBack }
- }
- --[[ Drawing Methods ]]--
- function printMenu( menu )
- for i=1,#menu do
- if i == selectedItem then
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- centerPrint(" "..menu[i].text.." ")
- else
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- centerPrint(" "..menu[i].text.." ")
- end
- end
- end
- --[[ Handlers ]]--
- 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
- function oItemSelected( menu )
- menu[selectedItem].handler()
- end
- function main()
- while inMainMenu do
- drawTitle()
- term.setBackgroundColor(colors.blue)
- centerPrint(" [ Main Menu ] ")
- centerPrint(" ")
- printMenu(mainMenu)
- term.setBackgroundColor(colors.blue)
- centerPrint(" ")
- local event, key = os.pullEvent("key")
- oKeyPressed(key,mainMenu)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement