Yuri_Pearce

ProjS API v2

Nov 16th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. --[[
  2.     CC ProjS API
  3.     v2
  4. ]]
  5.  
  6. function pack(inf)
  7.     if fs.exists(inf) == false then
  8.         return "packing failed:folder doesn't exists"
  9.     end
  10.     if fs.isDir(inf) == false then
  11.         return "packing failed:path is a file"
  12.     end
  13.     packing = true
  14.     checks = {
  15.         [inf] = false;
  16.     }
  17.     outpack = {
  18.         [inf] = true
  19.     }
  20.     while packing do
  21.         checked = 0
  22.         tempx = 0
  23.         for name in pairs(checks) do
  24.             tempx = tempx + 1
  25.             if checks[name] == true then
  26.                 checked = checked + 1
  27.             end
  28.         end
  29.         if checked == tempx then
  30.             packing = false
  31.         end
  32.         for name in pairs(checks) do
  33.             if checks[name] == false then
  34.                 listing = fs.list(name)
  35.                 for i = 1,#listing do
  36.                     path = name.."/"..listing[i]
  37.                     if fs.isDir(path) then
  38.                         checks[path] = false
  39.                         outpack[path] = true
  40.                     else
  41.                         file = fs.open(path,"r")
  42.                         filedata = file.readAll()
  43.                         file.close()
  44.                         outpack[path] = filedata
  45.                     end
  46.                 end
  47.                 checks[name] = true
  48.             end
  49.         end
  50.     end
  51.     outfile = fs.open(inf..".sp","w")
  52.     outfile.write(textutils.serialize(outpack))
  53.     outfile.close()
  54. end
  55.  
  56. function unpack(inf)
  57.     if fs.exists(inf) == false then
  58.         return "packing failed:file doesn't exists"
  59.     end
  60.     if fs.isDir(inf) then
  61.         return "packing failed:path is a folder"
  62.     end
  63.     file = fs.open(inf,"r")
  64.     packdata = textutils.unserialize(file.readAll())
  65.     file.close()
  66.     for name in pairs(packdata) do
  67.         if type(packdata[name]) == "boolean" then
  68.             path = name
  69.             if fs.exists(path) then
  70.                 path = "_"..path
  71.             end
  72.             fs.makeDir(path)
  73.         else
  74.            
  75.         end
  76.     end
  77.     for name in pairs(packdata) do
  78.         if type(packdata[name]) == "boolean" then
  79.            
  80.         else
  81.             path = name
  82.             if fs.exists(path) then
  83.                 path = "_"..name
  84.             end
  85.             file = fs.open(path,"w")
  86.             file.write(packdata[name])
  87.             file.close()
  88.         end
  89.     end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment