Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --set to WIRED modem side:
- local wiredModemSide="back"
- --currently only re-does fs functions that are actually usefull. some of them make me want to facepalm
- modem = peripheral.wrap(wiredModemSide)
- modem.open(1)
- --set old fs vars
- oldFS = {}
- for i,g in pairs(fs) do
- oldFS[i]=g
- end
- function listenForModemR(timeout)
- local timer = os.startTimer(timeout)
- while true do
- local evt,type,_,id,msg = coroutine.yield()
- if evt == "timer" and type == timer then
- return false
- elseif evt == "modem_message" then
- if id ==99 then --server id
- return msg,id
- end
- end
- end
- end
- function fs.open(file, mode)
- if not file or not mode then
- return false
- end
- --check if it's attempting to access ROM
- if string.sub(file,1,3) == "rom" then
- return oldFS.open(file,mode)
- else--we're good to run our code
- modem.transmit(1,1,"e "..file)
- doesExist, id = listenForModemR(1)
- if doesExist and id then
- if id==99 then
- --okay, it exists, now let's return our own special table
- local returnTable = {}
- if mode == "r" then
- --we need to do this in a string first so we can have variable code
- local env = {}
- env["modem"] = modem
- env["listenForModemR"] = listenForModemR
- env["textutils"] = textutils
- setmetatable(env,{__index=getfenv()})
- local writeDisString = 'modem.transmit(1,1,"g '..file..'") local msg=listenForModemR(10) if msg then return msg else return "Some sort of error" end'
- returnTable.read = loadstring(writeDisString)
- setfenv(returnTable.read, env)
- returnTable.readLine = returnTable.read
- function returnTable.close() end --nothing really needs to be done.
- --it's already been closed on the server. And if the user did not localize
- --the variable then it's their fault.
- return returnTable
- end
- end
- end
- if mode == "w" or mode =="a" then
- local returnTable={}
- writeDisString = ' args ={...}\nmodem.transmit(1,1,"w {\\""..args[1].."\\", \\"'..file..'\\"}")'
- theThing = loadstring(writeDisString)
- local env = {}
- env["textutils"]=textutils
- env["args"]=args
- setmetatable(env,{__index=_G})
- setfenv(theThing, env)
- function returnTable.write(...)
- args = {...}
- print"ran"
- theThing(unpack(args))
- end
- returnTable.writeLine=returnTable.write
- function returnTable.close()
- thisIsAnotherReallyLongVar = nil
- end
- function returnTable.flush() end--no need, but we don't want errors.
- return returnTable
- end
- end
- end
- function fs.exists(file)
- if not file then
- return false
- end
- modem.transmit(1,1,"e "..file)
- return listenForModemR(10)
- end
- function fs.copy(file1,file2)
- --first read the thingy
- local readDis = fs.open(file1,"r")
- local readDis=readDis.readAll()
- --we no has 2 close, remember?
- --write it
- local writeDis = fs.open(file2,"w")
- writeDis.write(readDis)
- writeDis.close() --good to close when writing
- end
- function fs.isReadOnly(path)
- path = string.sub(path,1,3)
- if path=="rom" then
- return true
- else
- return false
- end--I can gurantdamntee you nothing is read only on the server
- end
- function fs.makeDir(dir)
- modem.transmit(1,1,"m "..dir)
- end
- function fs.getFreeSpace(dir)
- --check where
- local dirSl = string.find(dir, "/")
- local dirS = string.sub(dir,1,dirSl-1)
- if dirS =="rom" then
- return oldFS.getFreeSpace(dir)
- elseif string.find(dir, "disk") then
- return oldFs.getFreeSpace(dir)
- else
- modem.transmit(1,1,"f")
- return listenForModemR(10)
- end
- end
- function fs.delete(dir)
- modem.transmit(1,1,"d "..dir)
- end
- function fs.move(dir,dir2)
- fs.copy(dir,dir2)
- fs.delete(dir)
- --this kind of crap is what makes me want to facepalm. fs is an incredably bloated mostly useless API
- --and only few functions do things that require more than a few lines!
- end
- function fs.isDir()
- return false
- end
- function fs.combine(thisFunction,isALoadOfCrap)
- if fs.exists(thisFunction) and fs.exists(isALoadOfCrap) then
- return thisFunction.."/"..isALoadOfCrap
- else
- return false
- end
- end
- --i will do io in a future version
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement