Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sfs={}
- for k,v in pairs(fs) do
- sfs[k]=v
- end
- function sfs.isReadOnly(file) -- AVR compatability
- local r,d=pcall(fs.isReadOnly,file)
- if not r then
- print(file.." errored!")
- return true
- else
- return d
- end
- end
- do
- local function serializeImpl(t)
- local sType = type(t)
- if sType == "table" then
- local lstcnt=0
- for k,v in pairs(t) do
- lstcnt = lstcnt + 1
- end
- local result = "{"
- local aset=1
- for k,v in pairs(t) do
- if k==aset then
- result = result..serializeImpl(v)..","
- aset=aset+1
- else
- result = result..("["..serializeImpl(k).."]="..serializeImpl(v)..",")
- end
- end
- result = result.."}"
- return result
- elseif sType == "string" then
- return string.gsub(string.gsub(string.format("%q",t),"\\\n","\\n"),"\n","\\n")
- elseif sType == "number" or sType == "boolean" or sType == "nil" then
- return tostring(t)
- elseif sType == "function" then
- local status,data=pcall(string.dump,t)
- if status then
- return 'func('..string.format("%q",data)..')'
- else
- error()
- end
- else
- error()
- end
- end
- function split(T,func)
- if func then
- T=func(T)
- end
- local Out={}
- if type(T)=="table" then
- for k,v in pairs(T) do
- Out[split(k)]=split(v)
- end
- else
- Out=T
- end
- return Out
- end
- local function serialize( t )
- t=split(t)
- return serializeImpl( t, tTracking )
- end
- local function unserialize( s )
- local func, e = loadstring( "return "..s, "serialize" )
- local funcs={}
- if not func then
- return e
- end
- setfenv( func, {
- func=function(S)
- local new={}
- funcs[new]=S
- return new
- end,
- })
- return split(func(),function(val)
- if funcs[val] then
- return loadstring(funcs[val])
- else
- return val
- end
- end)
- end
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- clear()
- local data={}
- local pending={"disk"}
- clear()
- print("packing...")
- local folders={}
- while true do
- if not pending[1] then
- for k,v in pairs(folders) do
- sfs.delete(v)
- end
- break
- end
- local file=pending[1]
- print(file)
- table.remove(pending,1)
- if (sfs.isReadOnly(file) or file==encryptapi) and file~="/" then
- elseif sfs.isDir(file) then
- if file~="/" then
- data[file]=false
- end
- for k,v in pairs(sfs.list(file)) do
- table.insert(pending,sfs.combine(file,v))
- end
- if not sfs.isReadOnly(file) then
- table.insert(folders,file)
- end
- else
- local file2=sfs.open(file,"r")
- if file2 then
- data[file]=file2.readAll()
- file2.close()
- else
- print(file.." is unreadable!")
- end
- end
- sleep(0)
- end
- rednet.broadcast(serialize(data))
- end
Advertisement
Add Comment
Please, Sign In to add comment