Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- CC ProjS API
- v2
- ]]
- function pack(inf)
- if fs.exists(inf) == false then
- return "packing failed:folder doesn't exists"
- end
- if fs.isDir(inf) == false then
- return "packing failed:path is a file"
- end
- packing = true
- checks = {
- [inf] = false;
- }
- outpack = {
- [inf] = true
- }
- while packing do
- checked = 0
- tempx = 0
- for name in pairs(checks) do
- tempx = tempx + 1
- if checks[name] == true then
- checked = checked + 1
- end
- end
- if checked == tempx then
- packing = false
- end
- for name in pairs(checks) do
- if checks[name] == false then
- listing = fs.list(name)
- for i = 1,#listing do
- path = name.."/"..listing[i]
- if fs.isDir(path) then
- checks[path] = false
- outpack[path] = true
- else
- file = fs.open(path,"r")
- filedata = file.readAll()
- file.close()
- outpack[path] = filedata
- end
- end
- checks[name] = true
- end
- end
- end
- outfile = fs.open(inf..".sp","w")
- outfile.write(textutils.serialize(outpack))
- outfile.close()
- end
- function unpack(inf)
- if fs.exists(inf) == false then
- return "packing failed:file doesn't exists"
- end
- if fs.isDir(inf) then
- return "packing failed:path is a folder"
- end
- file = fs.open(inf,"r")
- packdata = textutils.unserialize(file.readAll())
- file.close()
- for name in pairs(packdata) do
- if type(packdata[name]) == "boolean" then
- path = name
- if fs.exists(path) then
- path = "_"..path
- end
- fs.makeDir(path)
- else
- end
- end
- for name in pairs(packdata) do
- if type(packdata[name]) == "boolean" then
- else
- path = name
- if fs.exists(path) then
- path = "_"..name
- end
- file = fs.open(path,"w")
- file.write(packdata[name])
- file.close()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment