--[[ Local Variables and Tables ]]-- local tFiles = { textutils.urlEncode("E7A5BBT2"), -- main textutils.urlEncode("rRtD8513"), -- startup textutils.urlEncode("hB4aaYqv"), -- readme textutils.urlEncode("9hiypZV9"), -- icon 1 textutils.urlEncode("vyAZc6tJ"), -- luaide textutils.urlEncode("ru4Ppzcq"), -- icon fm textutils.urlEncode("P8jjsWag"), -- splash textutils.urlEncode("7MKvvA8B"), -- login layout textutils.urlEncode("sagFBLR7"), -- main bg textutils.urlEncode("pzDYEm0x"), -- main bg 2 textutils.urlEncode("pnzdr8FB"), -- file manager textutils.urlEncode("udDhEHeV"), -- npaintpro textutils.urlEncode("Ur9tN2Ct"), -- quicktils API textutils.urlEncode("LVtcJbNe"), -- settings API } local version = "1.0" local w,h = term.getSize() local selectedItem = 1 local inMainMenu = true local installing = false local uninstalling = false local appsMenu = false --[[ 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 "..version.." Installer ]") term.setBackgroundColor(colors.black) centerPrint("") centerPrint("") end function drawDownloadTitle() drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) term.setCursorPos(5,4) write("Download Status: ") 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/APIs") fs.makeDir("/AquaOS/Apps") fs.makeDir("/AquaOS/.backgrounds") fs.makeDir("/AquaOS/.icons") fs.makeDir("/AquaOS/.accounts") sleep(3) while installing do -- File 1 drawDownloadTitle() write("/AquaOS/Main") sFile = http.get("http://pastebin.com/raw.php?i="..tFiles[1]) local contents = sFile.readAll() sFile.close() local file = assert(fs.open("/AquaOS/Main","w")) file.write(contents) file.close() sleep(1) -- File 2 drawDownloadTitle() write("/AquaOS/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/Apps/FileManager","w")) file.write(contents) file.close() sleep(1) -- File 3 drawDownloadTitle() write("/AquaOS/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/Apps/NPaintPro","w")) file.write(contents) file.close() sleep(1) -- File 4 drawDownloadTitle() write("/AquaOS/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/APIs/QuickTils","w")) file.write(contents) file.close() sleep(1) -- File 5 drawDownloadTitle() write("/AquaOS/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/APIs/Settings","w")) file.write(contents) file.close() sleep(1) -- File 6 drawDownloadTitle() write("/AquaOS/.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/.icons/.icon","w")) file.write(contents) file.close() sleep(.5) -- File 7 drawDownloadTitle() write("/AquaOS/.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/.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("/AquaOS/.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/.backgrounds/.splash","w")) file.write(contents) file.close() sleep(.5) -- File 10 drawDownloadTitle() write("/AquaOS/.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/.backgrounds/.loginLayout","w")) file.write(contents) file.close() sleep(.5) -- File 11 drawDownloadTitle() write("/AquaOS/.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/.icons/.iconFM","w")) file.write(contents) file.close() sleep(.5) -- File 12 drawDownloadTitle() write("/AquaOS/.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/.backgrounds/.mainBG2","w")) file.write(contents) file.close() sleep(.5) -- File 13 drawDownloadTitle() write("/AquaOS/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/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) 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("(true/false) QuickTils: ") local fQT = read() drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) centerWrite("(true/false) fLib: ") local fFL = read() drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) centerWrite("(true/false) LuaIDE: ") local fIDE = read() drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) centerWrite("(true/false) NPaintPro: ") local fNPP = read() drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) centerWrite("(true/false) FileManager: ") local fFB = read() drawTitle() centerPrint("Removing AquaOS...") fs.makeDir("/AOSLeftovers") if fQT == "true" then fs.move("/AquaOS/APIs/QuickTils","/AOSLeftovers/QuickTils") elseif fQT == "false" then return false else error("Input recognisation failure.") end if fFL == "true" then fs.move("/AquaOS/APIs/fLib","AOSLeftovers/fLib") elseif fFL == "false" then return false else error("Input recognisation failure.") end if fIDE == "true" then fs.move("/AquaOS/Apps/LuaIDE","AOSLeftovers/LuaIDE") elseif fIDE == "false" then return false else error("Input recognisation failure.") end if fNPP == "true" then fs.move("/AquaOS/Apps/NPaintPro","AOSLeftovers/NPaintPro") elseif fNPP == "false" then return false else error("Input recognisation failure.") end if fFB == "true" then fs.move("/AquaOS/Apps/FileManager","AOSLeftovers/FileManager") elseif fFB == "false" then return false else error("Input recognisation failure.") end fs.delete("/AquaOS") fs.delete("/startup") sleep(2) drawTitle() term.setBackgroundColor(colors.white) term.setTextColor(colors.black) centerPrint("AquaOS has been removed. 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/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()