Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Whisk - File/Folder Transmitter for ComputerCraft
- by EldidiStroyrr
- Use the GUI by running w/o arguments
- get with
- pastebin get 7f7Mdhrx whisk
- std pb 7f7Mdhrx whisk
- std ld whisk whisk
- working on:
- -gui for file selection
- Whisk is now on SimSoft! Install w/ storecode jVELp2st
- --]]
- local channel = 2846
- local modem = peripheral.find("modem")
- local yield = function()
- os.queueEvent("yield")
- os.pullEvent("yield")
- end
- local displayHelp = function()
- local helptxt = [[
- Whisk - file/folder sender
- Syntax:
- whisk
- whisk send <path> [idfilter] [password]
- whisk receive [path] [idfilter] [password]
- ]]
- write(helptxt)
- end
- fixstr = function(str) --replaces those annoying tabs with spaces, which fixes encryption
- if not type(str) == "string" then return str end
- local fix = string.gsub(str,string.char(9)," ")
- return fix
- end
- local lddfm = {} --main API
- lddfm.scr_x, lddfm.scr_y = term.getSize()
- lddfm.scroll = 0
- lddfm.ypaths = {}
- lddfm.setPalate = function(_p)
- if type(_p) ~= "table" then
- _p = {}
- end
- lddfm.p = { --the DEFAULT color palate
- bg = _p.bg or colors.gray, -- whole background color
- d_txt = _p.d_txt or colors.yellow, -- directory text color
- d_bg = _p.d_bg or colors.gray, -- directory bg color
- f_txt = _p.f_txt or colors.white, -- file text color
- f_bg = _p.f_bg or colors.gray, -- file bg color
- p_txt = _p.p_txt or colors.black, -- path text color
- p_bg = _p.p_bg or colors.lightGray, -- path bg color
- close_txt = _p.close_txt or colors.gray, -- close button text color
- close_bg = _p.close_bg or colors.lightGray,-- close button bg color
- scr = _p.scr or colors.lightGray, -- scrollbar color
- scrbar = _p.scrbar or colors.gray, -- scroll tab color
- }
- end
- lddfm.setPalate()
- lddfm.foldersOnTop = function(floop,path)
- local output = {}
- for a = 1, #floop do
- if fs.isDir(fs.combine(path,floop[a])) then
- table.insert(output,1,floop[a])
- else
- table.insert(output,floop[a])
- end
- end
- return output
- end
- lddfm.filterFileFolders = function(list,path,_noFiles,_noFolders,_noCD,_doHidden)
- local output = {}
- for a = 1, #list do
- local entry = fs.combine(path,list[a])
- if fs.isDir(entry) then
- if entry == ".." then
- if not (_noCD or _noFolders) then table.insert(output,list[a]) end
- else
- if not ((not _doHidden) and list[a]:sub(1,1) == ".") then
- if not _noFolders then table.insert(output,list[a]) end
- end
- end
- else
- if not ((not _doHidden) and list[a]:sub(1,1) == ".") then
- if not _noFiles then table.insert(output,list[a]) end
- end
- end
- end
- return output
- end
- lddfm.isColor = function(col)
- for k,v in pairs(colors) do
- if v == col then
- return true, k
- end
- end
- return false
- end
- term.clearLine = function(x1,x2,_y,_bg,_char) --this doesn't break anything, I swear!!
- local cbg, bg = term.getBackgroundColor()
- local x,y = term.getCursorPos()
- local sx,sy = term.getSize()
- if type(_char) == "string" then char = _char else char = " " end
- if type(_bg) == "number" then
- if lddfm.isColor(_bg) then bg = _bg
- else bg = cbg end
- else bg = cbg end
- term.setCursorPos(x1 or 1, _y or y)
- term.setBackgroundColor(bg)
- if x2 then --it pains me to add an if statement to something as simple as this
- term.write((char or " "):rep(x2-x1))
- else
- term.write((char or " "):rep(sx-(x1 or 0)))
- end
- term.setBackgroundColor(cbg)
- term.setCursorPos(x,y)
- end
- lddfm.render = function(_x1,_y1,_x2,_y2,_rlist,_path,_rscroll,_canClose,_scrbarY)
- local tsv = term.current().setVisible
- local px,py = term.getCursorPos()
- if tsv then tsv(false) end
- local x1, x2, y1, y2 = _x1 or 1, _x2 or lddfm.scr_x, _y1 or 1, _y2 or lddfm.scr_y
- local rlist = _rlist or {"Invalid directory."}
- local path = _path or "And that's terrible."
- ypaths = {}
- local rscroll = _rscroll or 0
- for a = y1, y2 do
- term.clearLine(x1,x2,a,lddfm.p.bg)
- end
- term.setCursorPos(x1,y1)
- term.setTextColor(lddfm.p.p_txt)
- term.clearLine(x1,x2+1,y1,lddfm.p.p_bg)
- term.setBackgroundColor(lddfm.p.p_bg)
- term.write(("/"..path):sub(1,x2-x1))
- for a = 1,(y2-y1) do
- if rlist[a+rscroll] then
- term.setCursorPos(x1,a+(y1))
- if fs.isDir(fs.combine(path,rlist[a+rscroll])) then
- term.clearLine(x1,x2,a+(y1),lddfm.p.d_bg)
- term.setTextColor(lddfm.p.d_txt)
- term.setBackgroundColor(lddfm.p.d_bg)
- else
- term.clearLine(x1,x2,a+(y1),lddfm.p.f_bg)
- term.setTextColor(lddfm.p.f_txt)
- term.setBackgroundColor(lddfm.p.f_bg)
- end
- term.write(rlist[a+rscroll]:sub(1,x2-x1))
- ypaths[a+(y1)] = rlist[a+rscroll]
- else
- term.clearLine(x1,x2,a+(y1),lddfm.p.bg)
- end
- end
- local scrbarY = _scrbarY or math.ceil( (y1+1)+( (_rscroll/(#_rlist-(y2-(y1+1))))*(y2-(y1+1)) ) )
- for a = y1+1, y2 do
- term.setCursorPos(x2,a)
- if a == scrbarY then
- term.setBackgroundColor(lddfm.p.scrbar)
- else
- term.setBackgroundColor(lddfm.p.scr)
- end
- term.write(" ")
- end
- if _canClose then
- term.setCursorPos(x2-4,y1)
- term.setTextColor(lddfm.p.close_txt)
- term.setBackgroundColor(lddfm.p.close_bg)
- term.write("close")
- end
- term.setCursorPos(px,py)
- if tsv then tsv(true) end
- return scrbarY
- end
- lddfm.coolOutro = function(x1,y1,x2,y2,_bg,_txt,char)
- local cx, cy = term.getCursorPos()
- local bg, txt = term.getBackgroundColor(), term.getTextColor()
- term.setTextColor(_txt or colors.white)
- term.setBackgroundColor(_bg or colors.black)
- local _uwah = 0
- for y = y1, y2 do
- for x = x1, x2 do
- _uwah = _uwah + 1
- term.setCursorPos(x,y)
- term.write(char or " ")
- if _uwah >= math.ceil((x2-x1)*1.63) then sleep(0) _uwah = 0 end
- end
- end
- term.setTextColor(txt)
- term.setBackgroundColor(bg)
- term.setCursorPos(cx,cy)
- end
- lddfm.scrollMenu = function(amount,list,y1,y2)
- if #list >= y2-y1 then
- lddfm.scroll = lddfm.scroll + amount
- if lddfm.scroll < 0 then
- lddfm.scroll = 0
- end
- if lddfm.scroll > #list-(y2-y1) then
- lddfm.scroll = #list-(y2-y1)
- end
- end
- end
- --[[
- a quick explanation of the arguments:
- x1 and y1: top-left corner coordinates of menu window. defaults to the top-left corner of the screen
- x2 and y2: bottom-right corner coordinates of menu window. defaults to the bottom-right corner of the screen
- _path: path to start viewing. defaults to "/"
- _noFiles: whether or not to view files in the menu, mainly for picking a path for installing something. defaults to false
- _noFolders: whether or not to view folders in the menu, mainly for choosing a file to run or whatever. defaults to false
- _noCD: whether or not you can change the directory, mainly to limit choices to a single folder. defaults to false
- _noSelectFolders: whether or not you can select folders to return. defaults to false
- _doHidden: whether or not to hide hidden files (starts with "."). defaults to false
- _p: the palate. has: bg, d_txt, d_bg, f_txt, t_bg, p_txt, p_bg, scr, scrbar. 'd' is for directory, 'f' is for file, 'p' is for path bar.
- _canClose: whether or not you can click on the little top-right "Cancel" button.
- --]]
- local makeMenu = function(_x1,_y1,_x2,_y2,_path,_noFiles,_noFolders,_noCD,_noSelectFolders,_doHidden,_p,_canClose)
- if _noFiles and _noFolders then
- return false, "C'mon, man..."
- end
- if _x1 == true then
- return false, "arguments: x1, y1, x2, y2, path, noFiles, noFolders, noCD, noSelectFolders, doHidden, palate, canClose" -- a little help
- end
- lddfm.setPalate(_p)
- local path, list = _path or ""
- lddfm.scroll = 0
- local _pbg, _ptxt = term.getBackgroundColor(), term.getTextColor()
- local x1, x2, y1, y2 = _x1 or 1, _x2 or lddfm.scr_x, _y1 or 1, _y2 or lddfm.scr_y
- local keysDown = {}
- local _barrY
- while true do
- list = lddfm.foldersOnTop(lddfm.filterFileFolders(fs.list(path),path,_noFiles,_noFolders,_noCD,_doHidden),path)
- if (fs.getDir(path) ~= "..") and not (_noCD or _noFolders) then
- table.insert(list,1,"..")
- end
- _res, _barrY = pcall( function() return lddfm.render(x1,y1,x2,y2,list,path,lddfm.scroll,_canClose) end)
- if not _res then
- local tsv = term.current().setVisible
- if tsv then tsv(true) end
- error(_barrY)
- end
- local evt = {os.pullEvent()}
- if evt[1] == "mouse_scroll" then
- lddfm.scrollMenu(evt[2],list,y1,y2)
- elseif evt[1] == "mouse_click" then
- local butt,mx,my = evt[2],evt[3],evt[4]
- if (butt == 1 and my == y1 and mx <= x2 and mx >= x2-4) and _canClose then
- --lddfm.coolOutro(x1,y1,x2,y2)
- term.setTextColor(_ptxt) term.setBackgroundColor(_pbg)
- return false
- elseif ypaths[my] and (mx >= x1 and mx < x2) then --x2 is reserved for the scrollbar, breh
- if fs.isDir(fs.combine(path,ypaths[my])) then
- if _noCD or butt == 3 then
- if not _noSelectFolders or _noFolders then
- --lddfm.coolOutro(x1,y1,x2,y2)
- term.setTextColor(_ptxt) term.setBackgroundColor(_pbg)
- return fs.combine(path,ypaths[my])
- end
- else
- path = fs.combine(path,ypaths[my])
- lddfm.scroll = 0
- end
- else
- term.setTextColor(_ptxt) term.setBackgroundColor(_pbg)
- return fs.combine(path,ypaths[my])
- end
- end
- elseif evt[1] == "key" then
- keysDown[evt[2]] = true
- if evt[2] == keys.enter and not (_noFolders or _noCD or _noSelectFolders) then --the logic for _noCD being you'd normally need to go back a directory to select the current directory.
- --lddfm.coolOutro(x1,y1,x2,y2)
- term.setTextColor(_ptxt) term.setBackgroundColor(_pbg)
- return path
- end
- if evt[2] == keys.up then
- lddfm.scrollMenu(-1,list,y1,y2)
- elseif evt[2] == keys.down then
- lddfm.scrollMenu(1,list,y1,y2)
- end
- if evt[2] == keys.pageUp then
- lddfm.scrollMenu(y1-y2,list,y1,y2)
- elseif evt[2] == keys.pageDown then
- lddfm.scrollMenu(y2-y1,list,y1,y2)
- end
- if evt[2] == keys.home then
- lddfm.scroll = 0
- elseif evt[2] == keys["end"] then
- if #list > (y2-y1) then
- lddfm.scroll = #list-(y2-y1)
- end
- end
- if evt[2] == keys.h then
- if keysDown[keys.leftCtrl] or keysDown[keys.rightCtrl] then
- _doHidden = not _doHidden
- end
- end
- elseif evt[1] == "key_up" then
- keysDown[evt[2]] = false
- end
- end
- end
- local defaultKey = "swordfish" --the most secure.
- local tArg = {...}
- local mode, itPath, idfilter, enckey = tArg[1], tArg[2], tonumber(tArg[3]), tArg[4], tArg[5]
- filetree = {}
- if not enckey then
- enckey = defaultKey
- end
- if tArg[5] == "y" then
- doReadOnly = true
- else
- doReadOnly = false
- end
- --API made by valithor.
- local encrypt = function(msg,key)
- local num = ""
- for i = 1, #key do
- local let = key:sub(i,i):byte()
- num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
- num = #msg..num
- end
- math.randomseed(tonumber(num))
- local encrypt = ""
- for i = 1, #msg do
- local rotation = math.random(0,94)
- local byte = msg:sub(i,i):byte()
- local rotate = rotation+byte <= 127 and rotation +byte or ((rotation+byte)%127)+32
- encrypt = encrypt..string.char(rotate)
- end
- return encrypt
- end
- local decrypt = function(msg,key)
- local num = ""
- for i = 1, #key do
- local let = key:sub(i,i):byte()
- num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
- num = #msg..num
- end
- math.randomseed(tonumber(num))
- local decrypt = ""
- for i = 1, #msg do
- local rotation = math.random(0,94)
- local byte = msg:sub(i,i):byte()
- local rotate = byte-rotation >= 32 and byte-rotation or byte-rotation
- if rotate < 32 then
- rotate = rotate+95
- end
- decrypt = decrypt..string.char(rotate)
- end
- return decrypt
- end
- local tEnc = function(msg)
- return encrypt(encrypt(tostring(msg),enckey),tostring(math.floor(os.time()/2)))
- end
- local tDec = function(msg)
- return decrypt(decrypt(tostring(msg),enckey),tostring(math.floor(os.time()/2)))
- end
- listAll = function(_path, _files, noredundant) --Thanks Lyqyd!
- local path = _path or ""
- local files = _files or {}
- if #path > 1 then table.insert(files, path) end
- for _, file in ipairs(fs.list(path)) do
- local path = fs.combine(path, file)
- if fs.isDir(path) then
- listAll(path, files)
- else
- table.insert(files, path)
- end
- end
- if noredundant then
- for a = 1, #files do
- if fs.isDir(tostring(files[a])) then
- if #fs.list(tostring(files[a])) ~= 0 then
- table.remove(files,a)
- end
- end
- end
- end
- return files
- end
- local function choice(input)
- local event, button
- repeat
- event, button = os.pullEvent("key")
- if type(button) == "number" then button = keys.getName(button) end
- if button == nil then button = " " end
- until string.find(input, button)
- return button
- end
- local drawThing = function(text,y,t,b)
- local scr_x, scr_y = term.getSize()
- local _pt,_pb = term.getTextColor(), term.getBackgroundColor()
- if t then term.setTextColor(t) else term.setTextColor(colors.black) end
- if b then term.setBackgroundColor(b) else term.setBackgroundColor(colors.white) end
- term.setCursorPos(1,y-1)
- term.clearLine()
- term.setCursorPos((scr_x/2)-(#text/2),y)
- term.clearLine()
- print(text)
- term.clearLine()
- term.setTextColor(_pt)
- term.setBackgroundColor(_pb)
- end
- output = {}
- local send = function()
- if not fs.exists(itPath) then
- error("No such file.")
- end
- contents = {}
- rawContents = {}
- if not fs.isDir(itPath) then
- local file = fs.open(itPath,"r")
- line = ""
- local s = 0
- while line do
- line = file.readLine()
- if line then
- table.insert(rawContents,fixstr(line))
- table.insert(contents,tEnc(fixstr(line)))
- if s >= 64 then
- yield()
- s = 0
- else
- s = s + 1
- end
- end
- end
- filetree = {[fs.getName(itPath)] = {fyle = contents, dir = false}}
- file.close()
- output = {id = os.getComputerID(), files = filetree}
- else
- filelist = {}
- _filelist = listAll(itPath,nil,true)
- if not doReadOnly then
- for a = 1, #_filelist do
- if not fs.isReadOnly(_filelist[a]) then
- table.insert(filelist,_filelist[a])
- end
- end
- else
- filelist = _filelist
- end
- for a = 1, #filelist do
- local isDir
- contents = {}
- rawContents = {}
- if not fs.isDir(filelist[a]) then
- local file = fs.open(filelist[a],"r")
- local line = ""
- local s = 0
- while line do
- line = file.readLine()
- if line then
- table.insert(contents,tEnc(fixstr(line)))
- table.insert(rawContents,fixstr(line))
- if s >= 64 then
- yield()
- s = 0
- else
- s = s + 1
- end
- end
- end
- file.close()
- isDir = false
- else
- contents = {""}
- isDir = true
- end
- if fs.combine("",shell.resolve(itPath)) == "" then --This oughta fix things
- filelist[a] = fs.combine("root"..os.getComputerID(),filelist[a])
- end
- filetree[filelist[a]] = {fyle = contents, dir = isDir}
- end
- output = {id = os.getComputerID(), files = filetree}
- end
- modem.transmit(channel,channel,output)
- end
- local receive = function(GUImode)
- local combinedSize = 0
- local filecount = 0
- --local event, side, sendID, repChannel, msg
- while true do
- input = {}
- event, side, sendChannel, repChannel, msg = os.pullEvent()
- if event == "char" and string.lower(side) == "x" then
- if not GUImode then
- print("Cancelled.")
- end
- return 0,0,false
- end
- if type(msg) == "table" then
- if type(msg.files) == "table" and (idfilter or msg.id) == msg.id then
- if GUImode then
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing("Decrypting...",3)
- else
- print("Decrypting...")
- end
- break
- end
- end
- end
- for k,v in pairs(msg.files) do
- local fee
- if not itPath then
- fee = k
- else
- local slashpos = string.find(k,"/") or 1
- fee = fs.combine(itPath,k:sub(slashpos))
- end
- local doOverwrite = true
- if fs.exists(fee) and fee == k then
- if GUImode then
- drawThing("Overwrite '"..fee.."'? [Y/N]",6)
- else
- print("Overwrite '"..fee.."'? [Y/N]")
- end
- if choice("yn") == "n" then
- doOverwrite = false
- else
- doOverwrite = true
- end
- end
- if doOverwrite then
- filecount = filecount + 1
- if not fs.exists(fs.getDir(fee)) then fs.makeDir(fs.getDir(fee)) end
- if type(v) == "table" then
- if v.dir then
- fs.makeDir(fee)
- else
- local file = fs.open(fee,"w")
- if file then
- for a = 1, #v.fyle do
- file.writeLine(fixstr(tDec(v.fyle[a])))
- if a % 32 == 0 then
- yield()
- end
- end
- file.close()
- combinedSize = combinedSize + fs.getSize(fee)
- end
- end
- end
- end
- end
- return filecount, combinedSize, true
- end
- local sendGUI = function()
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing("Which file/folder?",3)
- itPath = makeMenu(1,5,_,_,_,_,_,_,_,_,_,true)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- if itPath == false then
- return false
- end
- if not fs.exists(itPath) then
- drawThing("Doesn't exist!",3)
- sleep(0.6)
- return false
- end
- term.clear()
- drawThing("Encryption key? (optional)",3)
- enckey = nil
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- write(">")
- sleep(0)
- enckey = read("*")
- if enckey == "" then enckey = defaultKey end
- drawThing("ID filter? (optional)",3)
- idfilter = nil
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- write(">")
- sleep(0)
- idfilter = tonumber(read())
- drawThing("Do read-only files/folders? (Y/N)",3)
- doReadOnly = false
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- sleep(0)
- local thing = choice("yn")
- if thing == "y" then doReadOnly = true else doReadOnly = false end
- local thang = "Encrypting"
- if idfilter then
- thang = thang.." for ID "..tostring(idfilter).."..."
- else
- thang = thang.."..."
- end
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing(thang,3)
- send()
- drawThing("Sent '"..itPath.."'!",3)
- sleep(0)
- return true
- end
- local receiveGUI = function()
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing("Save in what folder?",3)
- itPath = makeMenu(1,5,_,_,_,true,_,_,_,_,_,true)
- term.clear()
- drawThing("Name file? (optional)",3)
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- write(">")
- sleep(0)
- itPath = fs.combine(itPath,read())
- if string.gsub(itPath," ","") == "" then
- itPath = nil
- end
- drawThing("Decryption key? (optional)",3)
- enckey = nil
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- write(">")
- sleep(0)
- enckey = read("*")
- if enckey == "" then enckey = defaultKey end
- drawThing("Filter ID? (optional)",3)
- idfilter = nil
- term.setCursorPos(1,6)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- write(">")
- sleep(0)
- idfilter = tonumber(read())
- local thang = "Receiving"
- if idfilter then
- thang = thang.." from ID "..tostring(idfilter).."..."
- else
- thang = thang.."..."
- end
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing(thang,3)
- local count,size,success = receive(true)
- if success then
- drawThing("Received!",3)
- if count ~= 1 then
- drawThing("(Got "..count.." files)",5)
- else
- drawThing("(Got "..count.." file)",5)
- end
- if size ~= 1 then
- drawThing("(Totals "..size.." bytes)",7)
- else
- drawThing("(Totals "..size.." byte)",7)
- end
- else
- drawThing("Cancelled.",3)
- end
- sleep(0)
- return true
- end
- local gui = function()
- local scr_x, scr_y = term.getSize()
- local prevColor = term.getBackgroundColor()
- local evt = {}
- term.setBackgroundColor(colors.gray)
- term.clear()
- while true do
- term.setBackgroundColor(colors.gray)
- if res then term.clear() end
- drawThing("Whisk BETA",3)
- drawThing("(1) Send",7,colors.white,colors.black)
- drawThing("(2) Receive",11,colors.white,colors.black)
- drawThing("(X,Q) Exit",15,colors.white,colors.black)
- evt = {os.pullEvent()}
- local res = false
- sleep(0)
- if evt[1] == "mouse_click" then
- if evt[2] == 1 then
- if math.abs(evt[4] - 7) <= 1 then
- res = sendGUI()
- elseif math.abs(evt[4] - 11) <= 1 then
- res = receiveGUI()
- elseif math.abs(evt[4] - 15) <= 1 then
- res = true
- end
- end
- elseif evt[1] == "key" then
- if evt[2] == keys.one then
- res = sendGUI()
- elseif evt[2] == keys.two then
- res = receiveGUI()
- elseif evt[2] == keys.three or evt[2] == keys.q or evt[2] == keys.x then
- res = true
- end
- end
- if res then
- term.setCursorPos(1,scr_y)
- term.setBackgroundColor(prevColor)
- term.clearLine()
- break
- else
- term.setBackgroundColor(colors.gray)
- term.clear()
- end
- end
- end
- if modem then modem.open(channel) end
- waitForModem = function()
- while true do
- sleep(0)
- modem = peripheral.find("modem")
- if modem then
- return
- end
- end
- end
- if not tArg[1] then
- local prevBG, prevTXT = term.getBackgroundColor(), term.getTextColor()
- if modem then
- gui()
- else
- term.setBackgroundColor(colors.gray)
- term.clear()
- drawThing("You don't have a modem!",3)
- drawThing("Attach one or press a key.",5)
- sleep(0.1)
- local outcome = parallel.waitForAny(function() os.pullEvent("key") end, waitForModem)
- if modem then
- modem.open(channel)
- gui()
- else
- local scr_x,scr_y = term.getSize()
- term.setCursorPos(1,scr_y)
- term.setBackgroundColor(prevBG)
- term.setTextColor(prevTXT)
- term.clearLine()
- sleep(0)
- return false
- end
- end
- else
- if not modem then
- error("No modem detected.")
- end
- if mode == "send" then
- send()
- elseif mode == "receive" then
- write("Receiving")
- if idfilter then
- print(" from "..idfilter.."...")
- else
- print("...")
- end
- local fc, size = receive(false)
- write("Done. (got "..fc.." file")
- if fc ~= 1 then write("s") end
- write(", totalling "..size.." byte")
- if size ~= 1 then print("s)") else print(")") end
- else
- displayHelp()
- end
- end
- sleep(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement