Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lua Script System --
- -- set local variables
- local advanced = term.isColor()
- local scrwidth, scrheight = term.getSize()
- local oldsetTextColor = term.setTextColor
- local oldsetBackgroundColor = term.setBackgroundColor
- local splabg = colors.cyan
- local LuaSSdir = "LuaSS/"
- local loadingimage = paintutils.loadImage( LuaSSdir.."splash.txt")
- local folderStructureS
- _G.shell = shell
- -- set the new global os.pullEvent function
- function os.pullEvent(...)
- local eventType, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 = os.pullEventRaw(...)
- if eventType == "terminate" then
- error("Terminated installation", 0)
- return
- end
- return eventType, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
- end
- -- change color functions to fallback when not advanced computer
- if not advanced then
- function term.setTextColor( color )
- if color == colors.black then
- oldsetTextColor(color)
- else
- oldsetTextColor(colors.white)
- end
- end
- function term.setBackgroundColor( color )
- if color == colors.white then
- oldsetBackgroundColor(color)
- else
- oldsetBackgroundColor(colors.black)
- end
- end
- end
- -- draw a loading screen --
- term.setBackgroundColor( splabg )
- term.clear()
- if loadingimage then
- paintutils.drawImage(loadingimage, math.floor(scrwidth*.5 - 6), math.floor(scrheight*.5 - 2))
- end
- term.setCursorPos( 1, 1 )
- local loadingstring, oldloadingstring = "Starting Lua Script System for the first time...", ""
- if loadingimage then loadingstring = "Updating Lua Script System..." end
- local loadingframe = -scrwidth*.2
- local setCursorPos = term.setCursorPos
- local function drawLoadingProgressIndicator()
- while true do -- run a loop to prevent it from stopping the loading function before it returns.
- loadingframe = loadingframe + 1
- if loadingframe > scrwidth*1.2 then
- loadingframe = -scrwidth*.2
- end
- if loadingstring ~= oldloadingstring then
- setCursorPos( scrwidth*.5 - (#loadingstring*.5) + 1, scrheight - 1)
- term.setBackgroundColor( splabg )
- term.clearLine()
- term.write(loadingstring)
- end
- setCursorPos( loadingframe - 1, scrheight )
- term.setBackgroundColor( colors.blue )
- term.clearLine()
- term.setBackgroundColor( colors.lightBlue )
- term.write(string.rep(" ", scrwidth*.2))
- sleep()
- end
- end
- local function outOfSpaceError()
- term.setBackgroundColor(colors.blue)
- local outofspaceTitle = "Out of space"
- term.clear()
- term.setCursorPos((scrwidth - #outofspaceTitle)*.5, 1)
- term.write(outofspaceTitle)
- term.setCursorPos(1, 8)
- print("You need to free at least "..#folderStructureS - fs.getFreeSpace("").." bytes on your hard disk to install Lua Script System.")
- print("After freeing enough disk space restart the script.")
- error("Cannot continue installing Lua Script System!", 0)
- end
- local function createFolderForFile(path)
- local curpath = path
- local startHere = 1
- while true do
- local nextSlash = string.find(string.sub(path, startHere, -1), "/")
- if not nextSlash then return end
- nextSlash = nextSlash + startHere
- local folderToCreate = string.sub(curpath, 0, nextSlash - 1)
- if not fs.isDir(folderToCreate) then
- local ok, err = pcall(fs.makeDir, folderToCreate)
- if not ok then
- if string.find(err, "Out of space") then
- outOfSpaceError()
- end
- end
- end
- startHere = nextSlash
- end
- end
- local function installLuaScriptSystem()
- local urlToDownload = "https://pastebin.com/raw/c7jJgtgS"
- local handle = http.get(urlToDownload)
- folderStructureS = handle.readAll()
- handle.close()
- local folderStructure = textutils.unserialize(folderStructureS)
- if fs.getFreeSpace("") < #folderStructureS then
- loadingstring = "You are very low on space!!"
- end
- for k, v in pairs(folderStructure) do
- createFolderForFile(k)
- local file = fs.open(k, "w")
- if file then
- file.write(v)
- local ok, err = pcall(file.close)
- if not ok then
- if string.find(err, "Out of space") then
- outOfSpaceError()
- end
- end
- end
- sleep()
- end
- end
- parallel.waitForAny(drawLoadingProgressIndicator, installLuaScriptSystem)
- shell.run(LuaSSdir.."start")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement