Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- file download manager for use with pastebin
- function fileMgr()
- local pbget = "pastebin get "
- local rootFolder = "./pb"
- function forceType(val,typeOf)
- if type(val) == typeOf then
- return
- else
- local val = tostring(val)
- local typeOf = tostring(typeOf)
- error(val.." ".."not of type "..typeOf)
- end
- end
- function forceLengths(tables)
- local lastLength = false
- for i,v in pairs(tables) do
- local newLeng = table.getn(tables[i])
- if lastLength == false then
- -- variable not set yet
- local lastLength = newLeng
- else
- -- variable has been set before
- if lastLength ~= newLeng then
- error("tables must be of same size ")
- end
- end
- end
- end
- local pasteIDs = {}
- local pasteNames = {}
- local pasteNewFolders = {}
- function prepareFolder(newFolder)
- fs.makeDir(rootFolder..newFolder)
- end
- function newPasteForDir(name,newFolder,pasteID)
- forceType(name, "string")
- forceType(pasteID, "string")
- forceType(newFolder,"string")
- prepareFolder(newFolder)
- table.insert(pasteIDs,pasteID)
- table.insert(pasteNames,name)
- table.insert(pasteNewFolders,newFolder)
- end
- function getPastesForDir()
- forceLengths({pasteIDs,pasteNames,pasteNewFolders})
- for i,v in pairs(pasteNames) do
- local name = "/"..pasteNames[i]
- local targetFolder = rootFolder..pasteNewFolders[i]
- local pasteID = pasteIDs[i].." "
- local cmd = "pastebin ".."get "..pasteID..targetFolder..name
- shell.run(cmd)
- end
- end
- function confirmReplace()
- print("this will overwrite existing files. Continue? (Y)")
- local r = read()
- if r ~= "Y" then
- error("\n User declined")
- else
- fs.delete(rootFolder)
- end
- end
- function finishUp()
- shell.setDir(rootFolder)
- end
- return confirmReplace,newPasteForDir,finishUp,getPastesForDir
- end
- local confirmReplace,newPasteForDir,finishUp,getPastesForDir = fileMgr()
- confirmReplace()
- newPasteForDir("umnt-test.lua","/aaa/","8jgEcxkr")
- newPasteForDir("inmntnt.lua","/bbb/v/","Qx0t14Jr")
- getPastesForDir()
- finishUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement