--vars local file = [[--Packaged by pkg, a Badly-Programmed-Smash-Things-Togetherer program. --(c) Haddock, 2016 --Run me in a directory to extract it. ]] local tArgs = {...} local files = {}; local usingPassword = false local password = "" --functions local function addFolder(path, tree) for i, v in ipairs(fs.list(path)) do local subPath = path .. '/' .. v if v == '.DS_Store' or v == '.gitignore' or v == '.git' or subPath == '/rom' or subPath == '/'..shell.getRunningProgram() or v == '/'..shell.getRunningProgram() or v == "pkg" or v == "pkg.lua" or subPath == "pkg" or subPath == "pkg.lua" then print("Not including " .. v) elseif fs.isDir(subPath) then tree[v] = {} addFolder(subPath, tree[v]) else local h = fs.open(subPath, 'r') if h then tree[v] = h.readAll() h.close() end end end end local function rotateString(str, offset) return (str:gsub('%a', function(s) local base = s:lower() == s and ('a'):byte() or ('A'):byte() return string.char(((s:byte() - base + offset)%26)+base) end)) end --program addFolder(shell.dir(), files) write("Do you want a password [Y/N]? ") inp = read() print("") if inp:lower() == "y" then write("Password: ") inp = read(" ") write("Confirm: ") inpp = read(" ") if inp == inpp then usingPassword = true password = inpp end end print("Packing...") file = file .. 'local usingPassword = ' .. tostring(usingPassword) .. '\n' if usingPassword then local rotBy = 0 for i=1,#password do rotBy = rotBy + password:byte(i) end file = file .. 'local files = ' .. rotateString(textutils.serialize(files),rotBy) .. '\n' else file = file .. 'local files = ' .. textutils.serialize(files) .. '\n' end file = file .. [[ --rotate encryption, pretty weak but it works local function rotateString(str, offset) return (str:gsub('%a', function(s) local base = s:lower() == s and ('a'):byte() or ('A'):byte() return string.char(((s:byte() - base + offset)%26)+base) end)) end local function extract() local function node(path, tree) if type(tree) == 'table' then fs.makeDir(path) for k, v in pairs(tree) do node(path .. '/' .. k, v) end else local f = fs.open(path, 'w') if f then f.write(tree) f.close() end end end if usingPassword then print("This package is secured with a password.") print("Inputting the wrong password will extract the package,") print("but you will hold corrupt files.") write("Password: ") password = read(" ") local rotBy = 0 for i=1,#password do rotBy = rotBy - password:byte(i) end files = textutils.unserialize(rotateString(textutils.serialize(files),rotBy)) end node(shell.dir(), files) end extract() ]] local h = fs.open(shell.dir() .. '/out.pkg', 'w') h.write(file) h.close() print("Package wrote to " .. shell.dir() .. "/out.pkg")