Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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(_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 \"/\" if sDest == \"root\" then sDest = \"/\" end 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()
- print("Added file '".._path.."'")
- return _package
- end
- function addFolder(_package, _path)
- if string.sub(_path,1,string.len("rom"))=="rom" or string.sub(_path,1,string.len("/rom"))=="/rom" then
- print("Ignored 'rom' folder. (".._path..")")
- return
- end
- _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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement