Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local parta = [[
- if not http then
- error("HTTP required!", 0)
- end
- local function decode(text)
- local s = ""
- for k, char in ipairs({ text:byte(1, #text) }) do
- s = s..string.char(char+8)
- end
- return s
- end
- local oerror = error
- local function error(str, mode)
- return oerror("[ZIP API] "..str, mode)
- end
- local function getDir(path)
- local dir, file, tab = "", "", {}
- for t in path:gmatch("[^/]+") do
- table.insert(tab, t)
- end
- file = table.remove(tab, #tab)
- for k, v in ipairs(tab) do
- dir = dir.."/"..v
- end
- return file, (dir == "") and "/" or dir
- end
- local function confirm(text)
- print(text)
- local e, k
- repeat
- e, k = os.pullEvent("key")
- until k == keys.y or k == keys.n
- coroutine.yield()
- return (k == keys.y) and true or false
- end
- local function unzip(file)
- local f = fs.open(file, "r") or error("File '"..file.."' does not exist!", 0)
- -- Read file
- local c = f.readAll()
- -- Close
- f.close()
- -- Split into table and decode
- local t = {}
- for token in decode(c):gmatch("[^\n]+") do
- table.insert(t, token)
- end
- -- Check if it is zip file
- h = table.remove(t, 1)
- if h ~= "`ZIP`" then
- error("File is not ZIP file or it is corrupted", 0)
- end
- -- Print name
- print("Unpacking "..tostring(table.remove(t, 1)))
- -- Loop unpacking process
- while true do
- -- Raw full path
- local rawfullpath = table.remove(t, 1)
- -- Break if end of file
- if not rawfullpath then
- break
- end
- -- Get and print file path
- local fullpath = shell.dir().."/"..rawfullpath
- print(" File "..fullpath)
- -- Resolve path
- local file, dir = getDir(fullpath)
- -- Create dir
- if fs.exists(dir) and not fs.isDir(dir) then
- if not confirm("File "..dir.." exists. Overwrite? [y/n]") then error("This file has to be overwritten to unpack this zip!", 0) end
- end
- if not fs.exists(dir) then
- fs.makeDir(dir)
- end
- -- Open file
- if fs.exists(fullpath) then
- if not confirm("File "..fullpath.." exists. Overwrite? [y/n]") then error("This file has to be overwritten to unpack this zip!", 0) end
- fs.delete(fullpath) -- It it's dir
- end
- local f = fs.open(fullpath, "w")
- -- Unpack file
- local line = table.remove(t, 1)
- while line ~= "`STOP`" and line do
- f.writeLine(line)
- line = table.remove(t, 1)
- end
- f.close()
- end
- print("Done!")
- end
- ]]
- local partb = [[
- unzip("tmp_install_zip")
- ]]
- local args = {...}
- if #args ~= 2 then
- print("Usage: ziptoexe <zip> <output>")
- return
- end
- if not http then
- error("HTTP API required!", 0)
- end
- -- COPY FROM PASTEBIN PART
- -- Upload a file to pastebin.com
- -- Determine file to upload
- local sCode
- local sFile = args[1]
- local sPath = shell.resolve( sFile )
- if not fs.exists( sPath ) or fs.isDir( sPath ) then
- print( "No such file" )
- return
- end
- -- Read in the file
- local sName = fs.getName( sPath )
- local file = fs.open( sPath, "r" )
- local sText = file.readAll()
- file.close()
- -- POST the contents to pastebin
- print( "Uploading zip..." )
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(sText)
- )
- if response then
- print( "[UPLOAD] Success." )
- local sResponse = response.readAll()
- response.close()
- sCode = string.match( sResponse, "[^/]+$" )
- else
- print( "[UPLOAD] Failed." )
- return
- end
- -- END OF IT
- local f = fs.open(args[2], "w")
- f.writeLine(parta)
- f.writeLine("shell.run('pastebin', 'get', '"..sCode.."', 'tmp_install_zip')")
- f.writeLine(partb)
- f.close()
- print("Done!")
Add Comment
Please, Sign In to add comment