Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --jBackup by Jesusthekiller
- --License: GNU GPL
- --More here: www.jesusthekiller.com/license-gpl.html
- assert(http, "Enable HTTP API!")
- local api = {}
- api.clear = function()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- end
- api.cprint = function(t, mode)
- term.setCursorPos((52-#t)/2, ({term.getCursorPos()})[2])
- write(t)
- if not mode then write("\n") end
- end
- api.key = function(a, b)
- local r
- repeat
- e, r = os.pullEvent("key")
- until r == keys[a] or r == keys[b]
- coroutine.yield()
- return r == keys[a] and true or false
- end
- api.zip = function(p, r)
- local files = fs.list(p)
- for _,v in pairs(files) do
- os.queueEvent("fake")
- coroutine.yield()
- print(p.."/"..v)
- if fs.isDir(v) and v ~= "rom" then
- table.insert(r.dir, p.."/"..v)
- r = api.zip(p.."/"..v, r)
- elseif (not fs.isDir(v)) then
- local file = fs.open(v, "r") or error("Can not open "..p.."/"..v, 0)
- r.file[p.."/"..v] = file.readAll()
- file.close()
- end
- end
- return r
- end
- api.unzip = function(t)
- for _,v in ipairs(t.dir) do
- print(v)
- fs.makeDir(v)
- end
- for k,v in pairs(t.file) do
- print(k)
- local file = fs.open(k, "w") or error("Can not open "..v, 0)
- file.write(v)
- file.close()
- end
- end
- api.pastebin_put = function(t)
- print("Uploading...")
- local f= fs.open("oo", "w")
- f.write(t)
- f.close()
- local r = http.post("http://pastebin.com/api/api_post.php", "api_option=paste&api_dev_key=0ec2eb25b6166c0c27a394ae118ad829&api_paste_format=lua&api_paste_name=Backup&api_paste_code="..textutils.urlEncode(t))
- assert(r, "Could not upload to pastebin!")
- return string.match(r.readAll(), "[^/]+$")
- end
- api.pastebin_get = function(c)
- print("Downloading...")
- local r = http.get("http://pastebin.com/raw.php?i="..c)
- assert(r, "Could not download from pastebin!")
- return r.readAll()
- end
- api.clear()
- api.cprint("Welcome to jBackup v0.1!")
- api.cprint("Press 'p' for pack mode or 'u' for unpack mode")
- if api.key('p', 'u') then
- api.cprint("File uploaded, code: "..api.pastebin_put(textutils.serialize(api.zip("", {['dir'] = {}, ['file'] = {}}))))
- else
- api.cprint("Enter code:", true)
- api.unzip(textutils.unserialize(api.pastebin_get(read())))
- print("Done!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement