qwertz19281

[ComputerCraft] RemoteFS client

May 8th, 2016
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.32 KB | None | 0 0
  1. --Remote FS client modifier
  2.  
  3. orig_fslist=_G.fs.list
  4. _G.fs.list=function (pth)
  5.     if(string.sub(pth,1,3)=="::") then
  6.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  7.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  8.         rednet.send(id, {"list",modpth[2]},"remfs")
  9.         sid, msg = rednet.receive("remfs")
  10.         return msg
  11.     else
  12.       return orig_fslist(pth)
  13.     end
  14.   end
  15. orig_fsexists=_G.fs.exists
  16. _G.fs.exists=function (pth)
  17.     if(string.sub(pth,1,3)=="::") then
  18.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  19.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  20.         rednet.send(id, {"exists",modpth[2]},"remfs")
  21.         sid, msg = rednet.receive("remfs")
  22.         return msg
  23.     else
  24.       return orig_fsexists(pth)
  25.     end
  26.   end
  27. orig_fsisDir=_G.fs.isDir
  28. _G.fs.isDir=function (pth)
  29.     if(string.sub(pth,1,3)=="::") then
  30.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  31.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  32.         rednet.send(id, {"isDir",modpth[2]},"remfs")
  33.         sid, msg = rednet.receive("remfs")
  34.         return msg
  35.     else
  36.       return orig_fsisDir(pth)
  37.     end
  38.   end
  39. orig_fsisReadOnly=_G.fs.isReadOnly
  40. _G.fs.isReadOnly=function (pth)
  41.     if(string.sub(pth,1,3)=="::") then
  42.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  43.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  44.         rednet.send(id, {"isReadOnly",modpth[2]},"remfs")
  45.         sid, msg = rednet.receive("remfs")
  46.         return msg
  47.     else
  48.       return orig_fsisReadOnly(pth)
  49.     end
  50.   end
  51. orig_fsgetDrive=_G.fs.getDrive
  52. _G.fs.getDrive=function (pth)
  53.     if(string.sub(pth,1,3)=="::") then
  54.         return "remfs"
  55.     else
  56.       return orig_fsgetDrive(pth)
  57.     end
  58.   end
  59. orig_fsgetSize=_G.fs.getSize
  60. _G.fs.getSize=function (pth)
  61.     if(string.sub(pth,1,3)=="::") then
  62.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  63.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  64.         rednet.send(id, {"getSize",modpth[2]},"remfs")
  65.         sid, msg = rednet.receive("remfs")
  66.         return msg
  67.     else
  68.       return orig_fsgetSize(pth)
  69.     end
  70.   end
  71. orig_fsgetFreeSpace=_G.fs.getFreeSpace
  72. _G.fs.getFreeSpace=function (pth)
  73.     if(string.sub(pth,1,3)=="::") then
  74.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  75.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  76.         rednet.send(id, {"getFreeSpace",modpth[2]},"remfs")
  77.         sid, msg = rednet.receive("remfs")
  78.         return msg
  79.     else
  80.       return orig_fsgetFreeSpace(pth)
  81.     end
  82.   end
  83. orig_fsfind=_G.fs.find
  84. _G.fs.find=function (pth)
  85.     if(string.sub(pth,1,3)=="::") then
  86.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  87.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  88.         rednet.send(id, {"find",modpth[2]},"remfs")
  89.         sid, msg = rednet.receive("remfs")
  90.         return msg
  91.     else
  92.       return orig_fsfind(pth)
  93.     end
  94.   end
  95. orig_fsdelete=_G.fs.delete
  96. _G.fs.delete=function (pth)
  97.     if(string.sub(pth,1,3)=="::") then
  98.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  99.         if #modpth==1 then
  100.             return orig_fsdelete(pth)
  101.         end
  102.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  103.         rednet.send(id, {"delete",modpth[2]},"remfs")
  104.         sid, msg = rednet.receive("remfs")
  105.         return msg
  106.     else
  107.       return orig_fsdelete(pth)
  108.     end
  109.   end
  110. orig_fsmakeDir=_G.fs.makeDir
  111. _G.fs.makeDir=function (pth)
  112.     if(string.sub(pth,1,3)=="::") then
  113.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  114.         if #modpth==1 then
  115.             return orig_fsmakeDir(pth)
  116.         end
  117.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  118.         rednet.send(id, {"makeDir",modpth[2]},"remfs")
  119.         sid, msg = rednet.receive("remfs")
  120.         return msg
  121.     else
  122.       return orig_fsmakeDir(pth)
  123.     end
  124.   end
  125. _G.fs.readAll=function (pth)
  126.     if(string.sub(pth,1,3)=="::") then
  127.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  128.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  129.         rednet.send(id, {"readAll",modpth[2]},"remfs")
  130.         sid, msg = rednet.receive("remfs")
  131.         return msg
  132.     else
  133.       h=orig_fsopen(pth,"r")
  134.       srr=h.readAll()
  135.       h.close()
  136.       return h
  137.     end
  138.   end
  139. _G.fs.writeAll=function (pth,dta)
  140.     if(string.sub(pth,1,3)=="::") then
  141.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  142.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  143.         rednet.send(id, {"writeAll",modpth[2],dta},"remfs")
  144.         sid, msg = rednet.receive("remfs")
  145.         return msg
  146.     else
  147.       h=orig_fsopen(pth,"w")
  148.       h.write(dta)
  149.       h.close()
  150.       return h
  151.     end
  152.   end
  153. orig_fscopy=_G.fs.copy
  154. _G.fs.copy=function (pth,dest)
  155.     if(string.sub(pth,1,3)=="::") or (string.sub(dest,1,3)=="::") then
  156.     fs.writeAll(dest,fs.readAll(pth))
  157.     else
  158.         orig_fscopy(pth,dest)
  159.     end
  160.   end
  161. orig_fsmove=_G.fs.move
  162. _G.fs.move=function (pth,dest)
  163.     if(string.sub(pth,1,3)=="::") or (string.sub(dest,1,3)=="::") then
  164.     fs.writeAll(dest,fs.readAll(pth))
  165.     fs.delete(pth)
  166.     else
  167.         orig_fsmove(pth,dest)
  168.     end
  169.   end
  170. orig_fsopen=_G.fs.open
  171. _G.fs.open=function (pth,typ)
  172.     if(string.sub(pth,1,3)=="::") then
  173.         modpth=textutils.unserialize("{\""..string.gsub(pth, "/", "\",\"", 1).."\"}")
  174.         id=rednet.lookup("remfs", string.sub(modpth[1],3))
  175.         rednet.send(id, {"list",modpth[2]},"remfs")
  176.         sid, msg = rednet.receive("remfs")
  177.        
  178.         hand={}
  179.        
  180.             hand.hhid=nil
  181.             hand.id=nil
  182.            
  183.             hand.close=function ()
  184.                 id=rednet.lookup("remfs", rrrhost,3))
  185.                 rednet.send(id, {"close",nil,hhid},"remfsh")
  186.                 end
  187.                
  188.             hand.write=function (dta)
  189.                 rednet.send(id, {"write",dta,hhid},"remfsh")
  190.                 end
  191.        
  192.             hand.writeLine=function (dta)
  193.                 rednet.send(id, {"writeLine",dta,hhid},"remfsh")
  194.                 end
  195.                
  196.             hand.flush=function ()
  197.                 rednet.send(id, {"flush",nil,hhid},"remfsh")
  198.                 end
  199.                
  200.             hand.read=function ()
  201.                 rednet.send(id, {true,"read",nil,hhid},"remfs")
  202.                 sid, msg = rednet.receive("remfsh")
  203.                 return msg
  204.                 end
  205.                
  206.             hand.readLine=function ()
  207.                 rednet.send(id, {true,"readLine",nil,hhid},"remfs")
  208.                 sid, msg = rednet.receive("remfsh")
  209.                 return msg
  210.                 end
  211.                
  212.             hand.readAll=function ()
  213.                 rednet.send(id, {true,"readAll",nil,hhid},"remfs")
  214.                 sid, msg = rednet.receive("remfsh")
  215.                 return msg
  216.                 end
  217.         --}
  218.        
  219.         hand.hhid=msg
  220.         hand.id=rednet.lookup("remfsh", string.sub(modpth[1],3))
  221.        
  222.         return hand
  223.     else
  224.       return orig_fsopen(pth)
  225.     end
  226.   end
Add Comment
Please, Sign In to add comment