SHARE
TWEET

Example Package

Oeed Mar 17th, 2013 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local pkg = {["PkgMake"]="sPackage = \"local pkg = %@1 local function makeFile(_path, _content) local file = fs.open(_path, \\\"w\\\") _content = _content:gsub(\\\"\\!@\\\"..\\\"#&\\\", \\\"%\\\\n\\\") _content = textutils.unserialize(_content) file.write(textutils.unserialize(_content)) file.close() end local function makeFolder(_path, _content) fs.makeDir(_path) for k,v in pairs(_content) do if type(v) == \\\"table\\\" then makeFolder(_path .. \\\"/\\\" .. k, v) else makeFile(_path .. \\\"/\\\" .. k, v) end end end local sDest = shell.resolve( \\\"%@2\\\" ) or \\\"/\\\"local tPackage = pkg makeFolder(sDest, tPackage) print(\\\"Package Extracted to '\\\" .. sDest .. \\\"'!\\\")\"!@#&!@#&function addFile(_package, _path)!@#&  if fs.getName(_path) == \".DS_Store\" then!@#&          return _package!@#&     end!@#& local file, err = fs.open(_path, \"r\")!@#&     local content = file.readAll()!@#&      content = content:gsub(\"%\\n\", \"\\!@\"..\"#&\")!@#&  content = content:gsub(\"%%\", \"%%%%\")!@#&    _package[fs.getName(_path)] = content!@#&       file.close()!@#&        return _package!@#&end!@#&!@#&function addFolder(_package, _path)!@#&   _package = _package or {}!@#&   for _,f in ipairs(fs.list(_path)) do!@#&                local path = _path..\"/\"..f!@#&                if fs.isDir(path) then!@#&                      _package[fs.getName(f)] = addFolder(_package[fs.getName(f)], path)!@#&          else!@#&                        _package =  addFile(_package, path)!@#&         end!@#& end!@#& return _package!@#&end!@#&!@#&local tArgs = { ... }!@#&if #tArgs < 2 then!@#&   print( \"Usage: PkgMake <source> <destination>\" )!@#&  return!@#&end!@#&!@#&local sSource = shell.resolve( tArgs[1] )!@#&local sDest = shell.resolve( tArgs[2] )!@#&!@#&if fs.isDir( sDest ) then!@#&  error(\"Destination must not be a folder.\")!@#&end!@#&!@#&if sSource == sDest then!@#& error(\"Source can not be equal to destination.\")!@#&end!@#&!@#&if fs.exists( sSource ) and fs.isDir( sSource ) then!@#&       tPackage = {}!@#&       tPackage = addFolder(tPackage, sSource)!@#&     fPackage = fs.open(sDest,\"w\")!@#&!@#& sPackage = string.gsub(sPackage, \"%%@2\", fs.getName(sSource))!@#&     sPackage = string.gsub(sPackage, \"%%@1\", textutils.serialize(tPackage))!@#&   fPackage.write(sPackage)!@#&    fPackage.close()!@#&    print(\"Package Done! ('\" .. sDest .. \"'')\")!@#&     print(\"Type '\" .. sDest .. \"' to run it.\")!@#&else!@#&      error(\"Source does not exist or is not a folder.\")!@#&end",["Subfolder"]={["Sub-Sub-folder"]={["Yet Another File"]="our stuff",},["A File"]="our stuff",},} local function makeFile(_path, _content) local file = fs.open(_path, "w") _content = _content:gsub("!@".."#&", "%\n") _content = textutils.unserialize(_content) file.write(textutils.unserialize(_content)) file.close() end local function makeFolder(_path, _content) fs.makeDir(_path) for k,v in pairs(_content) do if type(v) == "table" then makeFolder(_path .. "/" .. k, v) else makeFile(_path .. "/" .. k, v) end end end local sDest = shell.resolve( "Package_Maker" ) or "/"local tPackage = pkg makeFolder(sDest, tPackage) print("Package Extracted to '" .. sDest .. "'!")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top