Advertisement
BigSHinyToys

[Computer Craft] packager mk2

Nov 19th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --[[
  2.         sys_packager
  3.         by BigSHinyToys
  4. ]]--
  5. local level = 0
  6. local sSlash = "/"
  7. local sSaveLoc = "Inst"
  8. local item = 0
  9.  
  10. local function err(input)
  11.     print("error "..tostring(input))
  12.     error()
  13. end
  14.  
  15. local partA = "["
  16. local partB = "="
  17. local partC = "]"
  18. local top = partA..partB..partB..partA
  19. local bottom = partC..partB..partB..partC
  20.  
  21. local function addFile(sDATA,path,name)
  22.     file = fs.open(sSaveLoc,"a")
  23.     if file then
  24.         file.write("local file"..item.." = "..top)
  25.         file.write(sDATA)
  26.         file.write(bottom.."\n")
  27.         file.write("local file"..item.."path = \""..path..name.."\"\n")
  28.         file.write("local file = fs.open(file"..item.."path,\"w\")\n")
  29.         file.write("file.write(file"..item..")\n")
  30.         file.write("file.close()\n")
  31.         file:close()
  32.         return true
  33.     else
  34.         err("add fiel faled")
  35.     end
  36. end
  37.  
  38. local function addDir(path)
  39.     file = fs.open(sSaveLoc,"a")
  40.     if file then
  41.         file.write("fs.makeDir(\""..path.."\")\n")
  42.         file:close()
  43.         return true
  44.     else
  45.         err("add dir failed")
  46.     end
  47. end
  48.  
  49. local function add(path)
  50.     level = level + 1
  51.     for k,v in pairs(fs.list(path)) do
  52.         if fs.isDir(path..sSlash..v) then
  53.             if level == 1 then
  54.                 if v ~= "rom" then
  55.                     addDir(path..sSlash..v)
  56.                     add(path..sSlash..v)
  57.                 end
  58.             else
  59.                 addDir(path..sSlash..v)
  60.                 add(path..sSlash..v)
  61.             end
  62.         else
  63.             item = item + 1
  64.             local file = fs.open(path..sSlash..v,"r")
  65.             local sData = file.readAll()
  66.             file.close()
  67.             addFile(sData,path..sSlash,v)
  68.         end
  69.     end
  70.     level = level - 1
  71. end
  72.  
  73. if fs.exists(sSaveLoc) and not fs.isDir(sSaveLoc) then
  74.     print("removing old "..sSaveLoc)
  75.     fs.delete(sSaveLoc)
  76. end
  77.  
  78. add("/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement