Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- CoreAPI is designed to provide some of the regularly needed
- features of general types of programs in one place.
- It is a mish-mash of functions where I wasn't sure where to place
- elsewhere.
- ]]
- version = "0.0.2"
- --==Startup Functions==--
- --Test This
- function setStartup(...)
- --Takes any number of arguments and creates
- --a startup script to execute the program (argument 1)
- --with any following parameters (arguments afterwards)
- local args = {...}
- --Making sure I don't break a previous startup
- if fs.exists("startup") then
- fs.move("startup", "oldStartup")
- end
- --Saving the params file
- if not fs.exists("tempFiles/") then
- fs.makeDir("tempFiles")
- end
- local tempStartupParams = fs.open("tempFiles/tempStartupParams", "w")
- tempStartupParams.write(textutils.serialize(args))
- tempStartupParams.close()
- --Generating the startup file
- local startupFile = fs.open("startup", "w")
- startupFile.writeLine("--If you can read this, remove it")
- startupFile.writeLine("local params = fs.open(\"tempFiles/tempStartupParams\", \"r\")")
- startupFile.writeLine("local args = textutils.unserialize(params.readAll())")
- startupFile.writeLine("params.close()")
- startupFile.writeLine("shell.run(unpack(args))")
- startupFile.close()
- end
- function removeStartup()
- --Removes the startup you created and sets old one
- --(if it exists), back to normal place
- --Removes set startup and puts new one back
- if fs.exists("oldStartup") then
- if fs.exists("startup") then
- fs.delete("startup")
- end
- fs.move("oldStartup", "startup")
- end
- --Gets rid of the tempFiles Folder
- if fs.exists("tempFiles") then
- fs.delete("tempFiles")
- end
- end
- function writeFile(table, filePath)
- if fs.exists(filePath) then
- return false
- else
- local f = fs.open(filePath, "w")
- f.write(textutils.serialize(table))
- f.close()
- return true
- end
- end
- function readFile(filePath)
- --This assumes it was written to by this API
- if fs.exists(filePath) then
- local f = fs.open(filePath, "r")
- local array = textutils.unserialize(f.readAll())
- f.close()
- return array
- end
- end
- --==Update Functions==--
- function pastebin(extension, fileName)
- --This will return JUST the code for HTML
- local pastebin = "http://www.pastebin.com/raw.php?i="..extension
- if fs.exists(fileName) then return false
- else
- local file = fs.open(fileName, "w")
- file.write(assert(http.get(pastebin)).readAll())
- file.close()
- return true
- end
- end
- function writeStartup(...)
- --Generates a startup program which will automatically update
- --programNames with URLs every reboot.
- --Work on this--
- end
Advertisement
Add Comment
Please, Sign In to add comment