Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if not pack then
- _G.pack = {}
- end
- local function pu()
- printError("pack <add/remove/dump/out/read> <input/output>")
- end
- local cmd = args[1] or ""
- if cmd == "add" then
- if fs.exists(args[2]) then
- local file = fs.open(args[2],"r")
- local r = file.readAll()
- pack[tostring(args[2])] = r
- file.close()
- print("Added File: "..tostring(args[2]))
- end
- elseif cmd == "out" then
- local file = fs.open(args[2],"w")
- local op = textutils.serialise(pack)
- file.write("local FILE = ")
- file.write(op)
- file.writeLine(" ")
- file.write([[
- for k,v in pairs(FILE) do
- local file = fs.open(k,'w')
- file.write(v)
- file.close()
- print("Wrote file: "..k)
- end
- ]])
- file.close()
- print("Created package file: "..tostring(args[2]))
- elseif cmd == "dump" then
- for k,v in pairs(pack) do
- print(k)
- end
- elseif cmd == "read" then
- if fs.exists(args[2]) then
- local file = fs.open(args[2],"r")
- local r = file.readAll()
- local ret = textutils.unserialise(r)
- file.close()
- for k,v in pairs(ret) do
- local file = fs.open(k,"w")
- file.write(v)
- file.close()
- print("Wrote File: "..k)
- end
- end
- elseif cmd == "remove" then
- pack[args[2]] = nil
- print("Removed File: "..args[2])
- else
- pu()
- end
Add Comment
Please, Sign In to add comment