Advertisement
BigSHinyToys

[Computer Craft] failed multi tasking shell

Nov 25th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 64.24 KB | None | 0 0
  1. local file1 = [==[if fs.exists("update") then
  2.   os.run(getfenv(),"update")
  3. end
  4. local split = true
  5. if split then
  6.   if fs.exists("SYS_MOUSE/split.lua") then
  7.     os.run(getfenv(),"SYS_MOUSE/split.lua","left")
  8.    else
  9.      print("Split unavalible")
  10.   end
  11. end
  12. print("system loading")
  13. for k,v in pairs(rs.getSides()) do
  14. print("Device "..v.." : "..(peripheral.getType(v) or ""))
  15. end
  16. print("checking system folder")
  17. if fs.exists("SYS_MOUSE") then
  18.   print("SYS_MOUSE located")
  19.   if fs.exists("SYS_MOUSE/apis") then
  20.     print("loading apis")
  21.     local list = fs.list("SYS_MOUSE/apis")
  22.     for k,v in pairs(list) do
  23.       os.loadAPI("SYS_MOUSE/apis/"..v)
  24.       print("loaded : "..v)
  25.     end
  26.   end
  27.   if fs.exists("SYS_MOUSE/kernal.lua") then
  28.     print("running kernal")
  29.     return os.run(getfenv(),"SYS_MOUSE/kernal.lua")
  30.   end
  31. else
  32.   error("system core not found\nplease contact system vendor\nreverting to craft os")
  33. end
  34. ]==]
  35. local file1path = "//startup"
  36. local file = fs.open(file1path,"w")
  37. file.write(file1)
  38. file.close()
  39. fs.makeDir("//SYS_MOUSE")
  40. local file2 = [==[--[[
  41.         simple kernal
  42.         with FS permitions / enviromant control
  43.         by BigSHinyToys
  44. ]]--
  45. function deepcopy(orig)
  46.     local copy
  47.     if type(orig) == 'table' then
  48.         copy = {}
  49.         for orig_key, orig_value in next, orig, nil do
  50.             if orig_key ~= "_G" then
  51.                 copy[deepcopy(orig_key)] = deepcopy(orig_value)
  52.             end
  53.         end
  54.         setmetatable(copy, deepcopy(getmetatable(orig)))
  55.     else -- number, string, boolean, etc
  56.         copy = orig
  57.     end
  58.     return copy
  59. end
  60.  
  61. local oldG = deepcopy(_G)
  62. local logFile = "sysErrorLog"
  63. local tThreads = {}
  64. local focused = 1
  65. local ver = 0.1
  66.  
  67. local function customFileSystem(root)
  68.     local newFS = {}
  69.     local backUpFS = fs
  70.     for k,v in pairs(fs) do
  71.         newFS[k] = function(path,...)
  72.             return backUpFS[k](root..path,...)
  73.         end
  74.     end
  75.     return newFS
  76. end
  77.  
  78. local function customFileSystemIO(root)
  79.     local newFS = {}
  80.     local backUpFS = io
  81.     for k,v in pairs(io) do
  82.         newFS[k] = function(path,...)
  83.             return backUpFS[k](root..path,...)
  84.         end
  85.     end
  86.     return newFS
  87. end
  88.  
  89. local function customRun(root)
  90.     local old = os.run
  91.     return function(env,path,...)
  92.         old(env,root..path,...)
  93.     end
  94. end
  95.  
  96. local function sysLog(sDATA)
  97.     file = fs.open(logFile,"a")
  98.     if file then
  99.         file.write(sDATA.."\n")
  100.         file:close()
  101.         return true
  102.     else
  103.         return false
  104.     end
  105. end
  106.  
  107. local function newThread(...)
  108.     sysLog("Thread Request :")
  109.     local input = {...}
  110.     local tEnv = deepcopy(oldG)
  111.     if input[1] == false then
  112.         tEnv.fs = customFileSystem("Users/admin")
  113.         tEnv.shell = {}
  114.         tEnv.shell.resolve = function(path) return path end
  115.         tEnv.io = customFileSystemIO("Users/admin")
  116.         tEnv.os.run = customRun("Users/admin")
  117.     end
  118.     tEnv.os.newThread = newThread
  119.     table.remove(input,1)
  120.     if input[1] and fs.exists(input[1]) then
  121.         sysLog("New Thread : "..tostring(input[1]))
  122.         local program = input[1]
  123.         table.remove(input,1)
  124.         table.insert(
  125.             tThreads,{
  126.                 parth = tostring(program),
  127.                 env = deepcopy(tEnv),
  128.                 main = coroutine.create(function(...) return os.run(tThreads[#tThreads].env,program,...) end)
  129.             }
  130.         )
  131.         sysLog("Thread Made : ")
  132.         sysLog("Input : "..#input)
  133.         local data = {}
  134.         for i = 1,#input do
  135.             table.insert(data,tostring(input[i]))
  136.         end
  137.         sysLog(table.concat(data,"\n"))
  138.        
  139.         local test = {coroutine.resume(tThreads[#tThreads].main,unpack(input))}
  140.         sysLog("First Output : ")
  141.         data = {}
  142.         for i = 1,#test do
  143.             table.insert(data,tostring(test[i]))
  144.         end
  145.         sysLog(table.concat(data," "))
  146.         sysLog("-- end Thread request --")
  147.     end
  148. end
  149.  
  150. sysLog("---- New log ----")
  151.  
  152. newThread(true,"SYS_MOUSE/shell.lua")
  153.  
  154. while true do
  155.     local event = {coroutine.yield()} -- non terminataible
  156.     local pos = 1
  157.     while pos <= #tThreads do
  158.         local test , req = coroutine.resume(tThreads[pos].main,unpack(event))
  159.         if coroutine.status(tThreads[pos].main) ~= "dead" and test then
  160.             pos = pos + 1
  161.         else
  162.             sysLog("Thread Crash "..#tThreads.." : "..coroutine.status(tThreads[pos].main).." "..tostring(tThreads[pos].parth).." "..tostring(req))
  163.             table.remove(tThreads,pos)
  164.             if #tThreads == 0 then
  165.                 local evnt,rand
  166.                 while rand ~= 28 do
  167.                     evnt,rand = os.pullEvent("key")
  168.                 end
  169.                 term.setBackgroundColor(colors.black)
  170.                 term.setTextColor(colors.white)
  171.                 term.clear()
  172.                 term.setCursorPos(1,1)
  173.                 print("System Crash loading old Shell")
  174.                 return
  175.             end
  176.         end
  177.     end
  178. end]==]
  179. local file2path = "//SYS_MOUSE/kernal.lua"
  180. local file = fs.open(file2path,"w")
  181. file.write(file2)
  182. file.close()
  183. fs.makeDir("//SYS_MOUSE/programs")
  184. local file3 = [==[--[[
  185.         Basic Testing and dignostic tool
  186.         by BigShinyToys
  187.         OPEN SOURCE CODE (no rights reserved)
  188. ]]--
  189.  
  190. -- varibles
  191. local BENCHver = 1.3
  192. local bRunning = true
  193. local tSideList = rs.getSides()
  194. local iTerminalID = os.getComputerID()
  195. local iPosq = 1
  196. -- functions
  197. local function menu(...) -- ver 0.1
  198.     local sel = 1
  199.     local list = {...}
  200.     local offX,offY = term.getCursorPos()
  201.     local curX,curY = term.getCursorPos()
  202.     while true do
  203.         if sel > #list then sel = 1 end
  204.         if sel < 1 then sel = #list end
  205.         for i = 1,#list do
  206.             term.setCursorPos(offX,offY+i-1)
  207.             if sel == i then
  208.                 print("["..list[i].."]")
  209.             else
  210.                 print(" "..list[i].." ")
  211.             end
  212.         end
  213.         while true do
  214.             local e,e1,e2,e3,e4,e5 = os.pullEvent()
  215.             if e == "key" then
  216.                 if e1 == 200 then -- up key
  217.                     sel = sel-1
  218.                     break
  219.                 end
  220.                 if e1 == 208 then -- down key
  221.                     sel = sel+1
  222.                     break
  223.                 end
  224.                 if e1 == 28 then
  225.                     term.setCursorPos(curX,curY)
  226.                     return list[sel],sel
  227.                 end
  228.             end
  229.         end
  230.     end
  231. end
  232. local function openRednet()
  233.     local listOfSides = rs.getSides()
  234.     for i = 1,6 do
  235.         if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
  236.             rednet.open(listOfSides[i])
  237.             return listOfSides[i]
  238.         end
  239.     end
  240. end
  241. -- apps
  242. local function RedstoneControl()
  243.     local e,e1,e2,e3,e4,e5
  244.     local function expand(iInput)
  245.         local tOutput = {}
  246.         local check = 32768
  247.         for i = 1,16 do
  248.             if iInput >= check then
  249.                 tOutput[i] = 1
  250.                 iInput = iInput - check
  251.             else
  252.                 tOutput[i] = 0
  253.             end
  254.             check = check/2
  255.         end
  256.         return tOutput
  257.     end
  258.     local function compact(tInput)
  259.         local iOutput = 0
  260.         local check = 1
  261.         for i = 16,1,-1 do
  262.             if tInput[i] == 1 then
  263.                 iOutput = iOutput + check
  264.             end
  265.             check = check*2
  266.         end
  267.         return iOutput
  268.     end
  269.     function test(sInput,offX,offY,curPos)
  270.         term.setCursorPos(offX,offY)
  271.         write(sInput)
  272.         offX = offX + 7
  273.         term.setCursorPos(offX,offY)
  274.         local iStatusB = rs.getBundledInput(sInput)
  275.         if peripheral.isPresent(sInput) then
  276.             write("                     ")-- blank's out the space for the name
  277.             term.setCursorPos(offX,offY)
  278.             write(peripheral.getType(sInput))
  279.         else
  280.             local invar = expand(iStatusB)
  281.             local text = ""
  282.             for i = 1,#invar do
  283.                 text = text..invar[i]
  284.             end
  285.             write(text)
  286.         end
  287.         local iStatusA = rs.getBundledOutput(sInput)
  288.         local invar = expand(iStatusA)
  289.         term.setCursorPos(offX+17,offY)
  290.         write(" "..tostring(rs.getInput(sInput)).." "..iStatusB.."        ")
  291.         term.setCursorPos(offX+17,offY+1)
  292.         write(" "..tostring(rs.getOutput(sInput)).." "..iStatusA.."        ")
  293.         term.setCursorPos(offX,offY+1)
  294.        
  295.         text = ""
  296.         for i = 1,#invar do
  297.             text = text..invar[i]
  298.         end
  299.         write(text)
  300.         term.setCursorPos(offX,offY+2)
  301.         write("                     ")
  302.         if curPos then
  303.             if curPos > 16 then
  304.                 spacer = 4
  305.             else
  306.                 spacer = 0
  307.             end
  308.             term.setCursorPos(offX+curPos-1+spacer,offY+2)
  309.             write("^")
  310.         end
  311.     end
  312.  
  313.     local tSideList = rs.getSides()
  314.     local curX,curY = 1,1
  315.     local spacer = 0
  316.     term.clear()
  317.     term.setCursorPos(1,1)
  318.    
  319.     while true do
  320.         if e == "key" then
  321.             if e1 == 14 then -- Backspace
  322.                 return
  323.             end
  324.             if e1 == 200 then -- up key
  325.                 curY = curY -1
  326.             end
  327.             if e1 == 208 then -- down key
  328.                 curY = curY +1
  329.             end
  330.             if e1 == 203 then -- left key
  331.                 curX = curX -1
  332.             end
  333.             if e1 == 205 then -- right key
  334.                 curX = curX +1
  335.             end
  336.             if e1 == 28 then
  337.                 if curX == 17 then
  338.                     if rs.getOutput(tSideList[curY]) then
  339.                         rs.setOutput(tSideList[curY],false)
  340.                     else
  341.                         rs.setOutput(tSideList[curY],true)
  342.                     end
  343.                 else
  344.                     local total = expand(rs.getBundledOutput(tSideList[curY]))
  345.                     if total[curX] == 1 then
  346.                         total[curX] = 0
  347.                     else
  348.                         total[curX] = 1
  349.                     end
  350.                     rs.setBundledOutput(tSideList[curY],compact(total))
  351.                 end
  352.             end
  353.         end
  354.         if curY > 6 then curY = 1 end
  355.         if curY < 1 then curY = 6 end
  356.         if curX > 17 then curX = 1 end
  357.         if curX < 1 then curX = 17 end
  358.         for o = 1,6 do
  359.             if o == curY then
  360.                 test(tSideList[o],1,o*3-2,curX)
  361.             else
  362.                 test(tSideList[o],1,o*3-2)
  363.             end
  364.         end
  365.         e,e1,e2,e3,e4,e5 = os.pullEvent()
  366.     end
  367. end
  368. local function Hardware()
  369.     term.clear()
  370.     term.setCursorPos(1,1)
  371.     print("Under Construction\nPress any key to return to menu.")
  372.     os.pullEvent("key")
  373.     return
  374. end
  375. local function wifi()
  376.     local bWiFiRun = true
  377.     local message
  378.     term.clear()
  379.     term.setCursorPos(1,1)
  380.     function readADV() -- slightly modified read function credit to dan200 for original
  381.         term.setCursorBlink( true )
  382.  
  383.         local sLine = ""
  384.         local nPos = 0
  385.  
  386.         local w, h = term.getSize()
  387.         local sx, sy = term.getCursorPos() 
  388.         local function redraw()
  389.             local nScroll = 0
  390.             if sx + nPos >= w then
  391.                 nScroll = (sx + nPos) - w
  392.             end
  393.                
  394.             term.setCursorPos( sx, sy )
  395.             term.write( string.rep(" ", w - sx + 1) )
  396.             term.setCursorPos( sx, sy )
  397.             term.write( string.sub( sLine, nScroll + 1 ) )
  398.             term.setCursorPos( sx + nPos - nScroll, sy )
  399.         end
  400.        
  401.         while true do
  402.             local sEvent, param = os.pullEvent()
  403.             if sEvent == "char" then
  404.                 sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  405.                 nPos = nPos + 1
  406.                 redraw()
  407.                
  408.             elseif sEvent == "key" then
  409.                 if param == 28 then -- Enter
  410.                     break
  411.                    
  412.                 elseif param == 203 then -- Left
  413.                     if nPos > 0 then
  414.                         nPos = nPos - 1
  415.                         redraw()
  416.                     end
  417.                    
  418.                 elseif param == 205 then -- Right
  419.                     if nPos < string.len(sLine) then
  420.                         nPos = nPos + 1
  421.                         redraw()
  422.                     end
  423.                    
  424.                 elseif param == 14 then
  425.                     -- Backspace
  426.                     if nPos > 0 then
  427.                         sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  428.                         nPos = nPos - 1                
  429.                         redraw()
  430.                     end
  431.                 end
  432.             else
  433.                 redraw()
  434.             end
  435.         end
  436.         term.setCursorBlink( false )
  437.         term.setCursorPos( w + 1, sy )
  438.         return sLine
  439.     end
  440.  
  441.     local function writer()
  442.         while true do
  443.             coroutine.yield()
  444.             writer2()
  445.         end
  446.     end
  447.  
  448.     function writer2()
  449.         term.setCursorPos(1,1)
  450.         term.clearLine()
  451.         if stat == "to" then
  452.             write("To  :")
  453.         elseif stat == "mes" then
  454.             write("Mes :")
  455.         elseif stat == "fail" then
  456.             write("No target specified press enter to continue.")
  457.         end
  458.     end
  459.  
  460.     local function send()
  461.         while true do
  462.             local sizX,sizY = term.getSize()
  463.             term.setCursorPos(6,1)
  464.             stat = "to"
  465.             writer2()
  466.             local id = readADV()
  467.             if id == "exit" then
  468.                 bWiFiRun = false
  469.                 rednet.close(modemOn)
  470.                 return
  471.             elseif id == "all" then
  472.                 id = nil
  473.                 term.setCursorPos(6,1)
  474.                 stat = "mes"
  475.                 writer2()
  476.                 message = readADV()
  477.                 rednet.send(id,message)
  478.             elseif tonumber(id) then
  479.                 id = tonumber(id)
  480.                 term.setCursorPos(6,1)
  481.                 stat = "mes"
  482.                 writer2()
  483.                 message = readADV()
  484.                 rednet.send(id,message)
  485.             else
  486.                 stat = "fail"
  487.                 writer2()
  488.                 os.pullEvent("key")
  489.             end
  490.         end
  491.     end
  492.  
  493.     local function recive()
  494.         local lastX,lastY = 1,2
  495.         while true do
  496.             term.setCursorBlink( true )
  497.             local event = {coroutine.yield()}
  498.             term.setCursorBlink( false )
  499.             if event[1] == "rednet_message" then
  500.                 local sizX,sizY = term.getSize()
  501.                 term.setCursorPos(1,lastY)
  502.                 print("Frm: "..event[2].." Dist: "..event[4].."M Mes: "..event[3])
  503.                 lastX,lastY = term.getCursorPos()
  504.             end
  505.         end
  506.     end
  507.  
  508.     -- moved openRednet from here
  509.     modemOn = openRednet()
  510.     if not modemOn then
  511.         print("No WIFI Modem\nPress any key to return to menu.")
  512.         os.pullEvent("key")
  513.         return
  514.     else
  515.         print("Opened wifi on "..modemOn.." side")
  516.     end
  517.  
  518.     term.clear()
  519.     term.setCursorPos(1,1)
  520.     local stat = nil
  521.  
  522.     local reciveHandel = coroutine.create(recive)
  523.     local writerHandel = coroutine.create(writer)
  524.     local sendHandel = coroutine.create(send)
  525.    
  526.     coroutine.resume(reciveHandel,e,e1,e2,e3,e4,e5)
  527.     coroutine.resume(writerHandel)
  528.     coroutine.resume(sendHandel,e,e1,e2,e3,e4,e5)
  529.    
  530.     while bWiFiRun do -- start a loop
  531.         local e,e1,e2,e3,e4,e5 = os.pullEvent()
  532.         coroutine.resume(reciveHandel,e,e1,e2,e3,e4,e5)
  533.         coroutine.resume(writerHandel)
  534.         coroutine.resume(sendHandel,e,e1,e2,e3,e4,e5)
  535.     end
  536. end
  537. local function EventMonitor()
  538.     term.clear()
  539.     term.setCursorPos(1,1)
  540.     print("press BACKSPACE key 14 to exit")
  541.     print("Wating For Event...")
  542.     local tEvents
  543.     while true do
  544.         tEvents = {os.pullEvent()}
  545.         if tEvents[1] == "key" and tEvents[2] == 14 then
  546.             return
  547.         end
  548.         for i = 1,#tEvents do
  549.             write(tostring(tEvents[i]).." ")
  550.         end
  551.         write("\n")
  552.     end
  553. end
  554. local function TurtleDriver()
  555.     term.clear()
  556.     term.setCursorPos(1,1)
  557.     if not turtle then
  558.         print("This is Not a Turtle \nPress any key to return")
  559.         os.pullEvent("key")
  560.         return
  561.     end
  562.     local compas = {"n","e","s","w"}
  563.     local turX,turY,turZ = 0,0,0
  564.     local gpsX,gpsY,gpsZ = nil , nil , nil
  565.     local face = 1
  566.     local slotSelX = 1
  567.     local slotSelY = 1
  568.     function move(ins,rep) -- low levle functions
  569.         if not ins and not rep then
  570.             return false,"error no move specified"
  571.         elseif not rep then
  572.             rep = 1
  573.         end
  574.         for i=1,rep do
  575.             if ins == "U" then -- up move
  576.                 if turtle.up() then
  577.                     turZ = turZ+1
  578.                 else
  579.                     return false
  580.                 end
  581.             end
  582.             if ins == "D" then -- down move
  583.                 if turtle.down() then
  584.                     turZ = turZ-1
  585.                 else
  586.                     return false
  587.                 end
  588.             end
  589.             if ins == "L" then -- left turn
  590.                 if turtle.turnLeft() then
  591.                     face = face - 1
  592.                     if face < 1 then
  593.                         face = 4   
  594.                     end
  595.                 else
  596.                     return false
  597.                 end
  598.             end
  599.             if ins == "R" then -- right turn
  600.                 if turtle.turnRight() then
  601.                     face = face + 1
  602.                     if face > 4 then
  603.                         face = 1   
  604.                     end
  605.                 else
  606.                     return false
  607.                 end
  608.             end
  609.             if ins == "F" then -- forward move
  610.                 if turtle.forward() then
  611.                     if face == 1 then
  612.                         turY = turY+1
  613.                     end
  614.                     if face == 2 then
  615.                         turX = turX+1
  616.                     end
  617.                     if face == 3 then
  618.                         turY = turY-1
  619.                     end
  620.                     if face == 4 then
  621.                         turX = turX-1
  622.                     end
  623.                 else
  624.                     return false
  625.                 end
  626.             end
  627.             if ins == "B" then -- back move
  628.                 if turtle.back() then
  629.                     if face == 1 then
  630.                         turY = turY-1
  631.                     end
  632.                     if face == 2 then
  633.                         turX = turX-1
  634.                     end
  635.                     if face == 3 then
  636.                         turY = turY+1
  637.                     end
  638.                     if face == 4 then
  639.                         turX = turX+1
  640.                     end
  641.                 else
  642.                     return false
  643.                 end
  644.             end
  645.         end
  646.         return true
  647.     end
  648.     local function reDraw()
  649.         term.clear()
  650.         term.setCursorPos(1,1)
  651.         print("Compus : "..compas[face].."  Loc : X "..turX.." Y "..turY.." Z "..turZ)
  652.         if gpsX then
  653.             print("last GPS ping   : X "..gpsX.." Y "..gpsY.." Z "..gpsZ)
  654.         else
  655.             print("GPS position unknown")
  656.         end
  657.         term.setCursorPos(1,3)
  658.         print("Remaning Fuel : "..turtle.getFuelLevel())
  659.         term.setCursorPos(1,5)
  660.         print([[Use "up down left right" keys to select slot then press "r" to refuel from slot.
  661. Press "g" locate GPS position.
  662. Press "b" to set Loc as GPS.
  663. Press "h" to ajust Heading]])
  664.     end
  665.     reDraw()
  666.     while true do
  667.         local e,e1,e2,e3,e4,e5 = os.pullEvent()
  668.         -- print(tostring(e).."-"..tostring(e1))
  669.         if e == "key" then
  670.             if e1 == 17 then
  671.                 move("F")
  672.             elseif e1 == 31 then
  673.                 move("B")
  674.             elseif e1 == 30 then
  675.                 move("L")
  676.             elseif e1 == 32 then
  677.                 move("R")
  678.             elseif e1 == 16 then
  679.                 move("U")
  680.             elseif e1 == 18 then
  681.                 move("D")
  682.             elseif e1 == 14 then -- backspace
  683.                 return
  684.             elseif e1 == 19 then -- r
  685.                 turtle.refuel(1)
  686.             elseif e1 == 34 then -- g
  687.                 local rednetSide = openRednet()
  688.                 if rednetSide then
  689.                     gpsX,gpsY,gpsZ = gps.locate( 2, false)
  690.                     rednet.close(rednetSide)
  691.                 else
  692.                     print("no WIFI modem connected")
  693.                 end
  694.             elseif e1 == 35 then -- h
  695.                 face = face +1
  696.                 if face > 4 then
  697.                     face = 1   
  698.                 end
  699.             elseif e1 == 200 then -- up turtle.select(e1-1)     local slotSelX = 1  local slotSelY = 1
  700.                 slotSelY = slotSelY -1
  701.                 if slotSelY < 1 then
  702.                     slotSelY = 4
  703.                 end
  704.             elseif e1 == 208 then -- down
  705.                 slotSelY = slotSelY +1
  706.                 if slotSelY > 4 then
  707.                     slotSelY = 1
  708.                 end
  709.             elseif e1 == 203 then -- left
  710.                 slotSelX = slotSelX -1
  711.                 if slotSelX < 1 then
  712.                     slotSelX = 4
  713.                 end
  714.             elseif e1 == 205 then -- right
  715.                 slotSelX = slotSelX +1
  716.                 if slotSelX > 4 then
  717.                     slotSelX = 1
  718.                 end
  719.             elseif e1 == 48 then -- b
  720.                 if gpsX then
  721.                     turX,turY,turZ = gpsX,gpsY,gpsZ
  722.                 end
  723.             end
  724.             turtle.select(slotSelX+(slotSelY*4)-4)
  725.         end
  726.         reDraw()
  727.     end
  728. end
  729. local function help() -- 203 left 205 right
  730. local tHelp = {
  731. [[This program is designed for use while testing other programs or redstone systems.
  732.  
  733. It allows you the user to change hardware settings quickly and read input from Redstone, Bundled Cable and WiFi.
  734.  
  735. Event Monitor will show what events happen. This is usefull for finding the number of a pressed key for example BackSpace is key 14.
  736.  
  737. OPEN SOURCE CODE (no rights reserved) 2012
  738. By Big Shiny Toys ver ]]..BENCHver.."\n\nPress Backspace to return to menu.",
  739. "section 2",
  740. "section 3",
  741. }
  742.     local iPage = 1
  743.     while true do
  744.     term.clear()
  745.     term.setCursorPos(1,1)
  746.     print(tHelp[iPage])
  747.     term.setCursorPos(10,18)
  748.     write("- Page "..iPage.." of "..#tHelp.." -")
  749.     local e,e1,e2 = os.pullEvent("key")
  750.         if e == "key" then
  751.             if e1 == 203 then -- left
  752.                 iPage = iPage - 1
  753.             elseif e1 == 205 then -- right
  754.                 iPage = iPage + 1
  755.             elseif e1 == 14 then -- Backspace
  756.                 return
  757.             end
  758.         end
  759.         if iPage < 1 then iPage = 1 end
  760.         if iPage > #tHelp then iPage = #tHelp end
  761.     end
  762. end
  763. -- Top Loop
  764. while bRunning do
  765.     term.clear()
  766.     term.setCursorPos(1,1)
  767.     print("Welcome to BENCH ver "..BENCHver.." terminal "..iTerminalID.."\nBy Big Shiny Toys")
  768.     term.setCursorPos(2,4)
  769.     term.setCursorBlink(false)
  770.     local selection = menu("Redstone","Hardware","WiFi","Event Monitor","Turtle Driver","Infomation/Help","Exit")
  771.     if selection == "Redstone" then
  772.         RedstoneControl()
  773.     elseif selection == "Hardware" then
  774.         Hardware()
  775.     elseif selection == "WiFi" then
  776.         wifi()
  777.     elseif selection == "Event Monitor" then
  778.         EventMonitor()
  779.     elseif selection == "Turtle Driver" then
  780.         TurtleDriver()
  781.     elseif selection == "Infomation/Help" then
  782.         help()
  783.     elseif selection == "Exit" then
  784.         bRunning = false
  785.     end
  786. end
  787. term.clear()
  788. term.setCursorPos(1,1)]==]
  789. local file3path = "//SYS_MOUSE/programs/Bench.lua"
  790. local file = fs.open(file3path,"w")
  791. file.write(file3)
  792. file.close()
  793. local file4 = [==[--[[
  794.         Mouse File Browser
  795.         by:
  796.             Stiepen irc(Kilobyte)
  797.             Cruor
  798.             BigSHinyToys
  799.        
  800.         note: send link to nightin9ale on CC forums
  801. --]]
  802.  
  803. local tArgs = {...}
  804. local ver = "1.0"
  805. local sTitle = "File Browser"
  806. local bugTest, norun, dir, showAll
  807. local _tArgs = {}
  808.  
  809. local function help()
  810.   print("Usage: browser [-d] [-h] [-a] [--debug] [--help] [--dir <dir>] [--all]")
  811.   print("--debug or -d: enable debug mode")
  812.   print("--help or -h: display this screen")
  813.   print("--dir: define initial directory")
  814.   print("--all or -a: show hidden files")
  815.   print("-u: update")
  816. end
  817.  
  818. for a = 1, #tArgs do
  819.     if tArgs[a]:sub(1,2) == "--" then
  820.         local cmd = tArgs[a]:sub(3):lower()
  821.         if cmd == "debug" then
  822.             bugTest = true
  823.         elseif cmd == "help" then
  824.             help()
  825.             norun = true
  826.         elseif cmd == "dir" then
  827.             dir = tArgs[a+1]
  828.             a = a + 1
  829.         elseif cmd == "all" then
  830.             showAll = true
  831.         end
  832.     elseif tArgs[a]:sub(1,1) == "-" then
  833.         for b = 2, #tArgs[a] do
  834.             cmd = tArgs[a]:sub(b, b)
  835.             if cmd == "d" then
  836.                 bugTest = true
  837.             elseif cmd == "h" then
  838.                 help()
  839.                 norun = true
  840.             elseif cmd == "p" then
  841.                 dir = tArgs[a+1]
  842.                 a = a + 1
  843.             elseif cmd == "a" then
  844.                 showAll = true
  845.             elseif cmd == "u" then
  846.  
  847.                 print("Checking for Updates")
  848.                 local isHTTP = false
  849.                 local response
  850.                 if http then
  851.                     isHTTP = true
  852.                     print("http on")
  853.                     response = http.get("http://pastebin.com/raw.php?i=rLbnyM1U")
  854.                 end
  855.                 local flag = false
  856.                 local isNewFlag = false
  857.                 local newVerID
  858.                 if response and isHTTP then
  859.                     print("recived")
  860.                     local sInfo = response.readLine()
  861.                     print(sInfo)
  862.                     while sInfo do
  863.                         print(sInfo)
  864.                         if flag then
  865.                             if sInfo == ver then
  866.                                 print("Mouse File Browser is up to date")
  867.                                 break
  868.                             else
  869.                                 newVerID = sInfo
  870.                                 flag = false
  871.                                 isNewFlag = true
  872.                             end
  873.                         elseif sInfo == sTitle then
  874.                             flag = true
  875.                         elseif isNewFlag then
  876.                             isNewFlag = sInfo
  877.                             response.close()
  878.                             break
  879.                         end
  880.                         sInfo = response.readLine()
  881.                     end
  882.                     if isNewFlag then
  883.                         print("New vershion avalible "..newVerID)
  884.                         print('downloading to \Browser')
  885.                         if fs.exists("Browser") then
  886.                             write("Browser exists OverWrite Browser Y/N : ")
  887.                             local input = string.lower(read())
  888.                             while input ~= "y" and input ~= "n" do
  889.                                 print("y or n required")
  890.                                 input = string.lower(read())
  891.                             end
  892.                             if input == "y" then
  893.                                 print("Over Writeing Browser")
  894.                                 print("Downloading new File")
  895.                                 local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag)
  896.                                 if response then
  897.                                     print("file downloaded")
  898.                                     print("installing")
  899.                                     fs.delete("Browser")
  900.                                     local handel = fs.open("Browser","w")
  901.                                     if handel then
  902.                                         handel.write(response.readAll())
  903.                                         handel.close()
  904.                                         print("Update Complete")
  905.                                     end
  906.                                     response.close()
  907.                                 end
  908.                             else
  909.                                 print("Update aborted")
  910.                             end
  911.                         else
  912.                             print("Downloading new File")
  913.                             local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag)
  914.                             if response then
  915.                                 print("file downloaded")
  916.                                 print("installing")
  917.                                 local handel = fs.open("Browser","w")
  918.                                 if handel then
  919.                                     handel.write(response.readAll())
  920.                                     handel.close()
  921.                                     print("Update Complete")
  922.                                 end
  923.                                 response.close()
  924.                             end
  925.                         end
  926.                     end
  927.                 elseif isHTTP then
  928.                     print("Error downloading update file Please contact BigSHinyToys on the CC forums")
  929.                     print("http://www.computercraft.info/forums2/index.php?/topic/5509-advanced-computer-mouse-file-browser/")
  930.                 elseif not isHTTP then
  931.                     print("HTTP API is turned off")
  932.                     print("Access Computer Craft Configer and change line")
  933.                     print([[enableapi_http {
  934. # Enable the "http" API on Computers
  935. general=false
  936. }
  937. TO THIS :
  938. enableapi_http {
  939. # Enable the "http" API on Computers
  940. general=true
  941. }]])
  942.                 end
  943.                 notCMD = false
  944.                 norun = true
  945.             end
  946.         end
  947.     else
  948.         table.insert(_tArgs, tArgs[a])
  949.     end
  950. end
  951.  
  952. if (not dir) and shell and shell.dir then
  953.     dir = shell.dir()
  954. end
  955.  
  956. if dir and shell and shell.resolve then
  957.     dir = shell.resolve(dir)
  958. end
  959.  
  960. dir = dir or "/"
  961.  
  962. if bugTest then -- this is that the var is for testing
  963.     print("Dir: "..dir)
  964.     os.startTimer(4)
  965.     os.pullEvent()
  966. end
  967.  
  968. local function clear()
  969.     term.setBackgroundColor(colors.black)
  970.     term.setTextColor(colors.white)
  971.     term.clear()
  972.     term.setCursorBlink(false)
  973.     term.setCursorPos(1,1)
  974. end
  975.  
  976. --[[
  977.         Code thanks to Cruor
  978.         http://www.computercraft.info/forums2/index.php?/topic/5802-support-for-shell/
  979. ]]--
  980. local function fixArgs(...)
  981.     local tReturn={}
  982.     local str=table.concat({...}," ")
  983.     local sMatch
  984.     while str and #str>0 do
  985.         if string.sub(str,1,1)=="\"" then
  986.             sMatch, str=string.match(str, "\"(.-)\"%s*(.*)")
  987.         else
  988.             sMatch, str=string.match(str, "(%S+)%s*(.*)")
  989.         end
  990.         table.insert(tReturn,sMatch)
  991.     end
  992.     return tReturn
  993. end
  994. --[[ end Cruor function ]]--
  995.  
  996.  
  997. -- modified read made to play nice with coroutines
  998.  
  999. local function readMOD( _sReplaceChar, _tHistory,_wdth)
  1000.     local sLine = ""
  1001.     term.setCursorBlink( true )
  1002.  
  1003.     local nHistoryPos = nil
  1004.     local nPos = 0
  1005.     if _sReplaceChar then
  1006.         _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  1007.     end
  1008.    
  1009.     local sx, sy = term.getCursorPos() 
  1010.  
  1011.     local w, h = term.getSize()
  1012.     if _wdth and type(_wdth) == "number" then
  1013.         w = sx + _wdth - 1
  1014.     end
  1015.    
  1016.     local function redraw( _sCustomReplaceChar )
  1017.         local nScroll = 0
  1018.         if sx + nPos >= w then
  1019.             nScroll = (sx + nPos) - w
  1020.         end
  1021.            
  1022.         term.setCursorPos( sx + _wdth - 1, sy )
  1023.         term.write(" ")
  1024.         term.setCursorPos( sx, sy )
  1025.         local sReplace = _sCustomReplaceChar or _sReplaceChar
  1026.         if sReplace then
  1027.             term.write( string.rep(sReplace,_wdth) )
  1028.         else
  1029.             term.write( string.sub( sLine, nScroll + 1 ,nScroll + _wdth) )
  1030.         end
  1031.         term.setCursorPos( sx + nPos - nScroll, sy )
  1032.     end
  1033.    
  1034.     while true do
  1035.         local sEvent, param = os.pullEvent()
  1036.         if sEvent == "char" then
  1037.             sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  1038.             nPos = nPos + 1
  1039.             redraw()
  1040.            
  1041.         elseif sEvent == "key" then
  1042.            
  1043.             if param == keys.left then
  1044.                 -- Left
  1045.                 if nPos > 0 then
  1046.                     nPos = nPos - 1
  1047.                     redraw()
  1048.                 end
  1049.                
  1050.             elseif param == keys.right then
  1051.                 -- Right               
  1052.                 if nPos < string.len(sLine) then
  1053.                     nPos = nPos + 1
  1054.                     redraw()
  1055.                 end
  1056.            
  1057.             elseif param == keys.up or param == keys.down then
  1058.                 -- Up or down
  1059.                 if _tHistory then
  1060.                     redraw(" ");
  1061.                     if param == keys.up then
  1062.                         -- Up
  1063.                         if nHistoryPos == nil then
  1064.                             if #_tHistory > 0 then
  1065.                                 nHistoryPos = #_tHistory
  1066.                             end
  1067.                         elseif nHistoryPos > 1 then
  1068.                             nHistoryPos = nHistoryPos - 1
  1069.                         end
  1070.                     else
  1071.                         -- Down
  1072.                         if nHistoryPos == #_tHistory then
  1073.                             nHistoryPos = nil
  1074.                         elseif nHistoryPos ~= nil then
  1075.                             nHistoryPos = nHistoryPos + 1
  1076.                         end                    
  1077.                     end
  1078.                    
  1079.                     if nHistoryPos then
  1080.                         sLine = _tHistory[nHistoryPos]
  1081.                         nPos = string.len( sLine )
  1082.                     else
  1083.                         sLine = ""
  1084.                         nPos = 0
  1085.                     end
  1086.                     redraw()
  1087.                 end
  1088.             elseif param == keys.backspace then
  1089.                 -- Backspace
  1090.                 if nPos > 0 then
  1091.                     redraw(" ");
  1092.                     sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  1093.                     nPos = nPos - 1                
  1094.                     redraw()
  1095.                 end
  1096.             elseif param == keys.home then
  1097.                 -- Home
  1098.                 nPos = 0
  1099.                 redraw()       
  1100.             elseif param == keys.delete then
  1101.                 if nPos < string.len(sLine) then
  1102.                     redraw(" ");
  1103.                     sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )              
  1104.                     redraw()
  1105.                 end
  1106.             elseif param == keys["end"] then
  1107.                 -- End
  1108.                 nPos = string.len(sLine)
  1109.                 redraw()
  1110.             end
  1111.         elseif sEvent == "redraw" then
  1112.             redraw()
  1113.         elseif sEvent == "return" then
  1114.             term.setCursorBlink( false )
  1115.             return sLine
  1116.         end
  1117.     end
  1118.    
  1119.     term.setCursorBlink( false )
  1120.    
  1121.     return sLine
  1122. end
  1123.  
  1124. -- end modified read
  1125.  
  1126. local function printC(posX,posY,textCol,backCol,text)
  1127.     term.setCursorPos(posX,posY)
  1128.     term.setTextColor(colors[textCol] or textCol)
  1129.     term.setBackgroundColor(colors[backCol] or backCol)
  1130.     term.write(text)
  1131. end
  1132.  
  1133. local function InputBox(title)
  1134.     local boxW,boxH = 26,3
  1135.     local termX,termY = term.getSize()
  1136.     local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left
  1137.     local options = {"ok","cancel"}
  1138.    
  1139.     local selected = 1
  1140.     local space = 0
  1141.     local range = {}
  1142.     for i = 1,#options do
  1143.         range[i] = {s = space,f = space + string.len(options[i])}
  1144.         space = space + string.len(options[i])+3
  1145.     end
  1146.     local ofC = (boxW/2) - (space/2)
  1147.    
  1148.     local function drawBox()
  1149.         printC(ofsX,ofsY,colors.black,colors.blue,string.rep(" ",boxW))
  1150.         printC(ofsX+1,ofsY,colors.black,colors.blue,(title or "User Input"))
  1151.         printC(ofsX,ofsY+1,colors.black,colors.white,string.rep(" ",boxW))
  1152.         printC(ofsX,ofsY+2,colors.black,colors.white,string.rep(" ",boxW))
  1153.         printC(ofsX,ofsY+3,colors.black,colors.white,string.rep(" ",boxW))
  1154.        
  1155.         for i = 1,#options do
  1156.             if i == selected then
  1157.                 term.setBackgroundColor(colors.lightGray)
  1158.                 term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
  1159.                 term.write("["..options[i].."]")
  1160.                 term.setBackgroundColor(colors.white)
  1161.                 term.write(" ")
  1162.             else
  1163.                 term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
  1164.                 term.write(" "..options[i].." ")
  1165.             end
  1166.         end
  1167.        
  1168.         printC(ofsX+2,ofsY+2,colors.black,colors.lightGray,string.rep(" ",boxW-4))
  1169.     end
  1170.     drawBox()
  1171.     term.setCursorPos(ofsX+2,ofsY+2)
  1172.     local co = coroutine.create(function() return readMOD(nil,nil,boxW - 4) end)
  1173.     while true do
  1174.         local event = {os.pullEvent()}
  1175.         if event[1] == "key" or event[1] == "char" then
  1176.             if event[2] == 28 then
  1177.                 local test,data = coroutine.resume(co,"return")
  1178.                 return data
  1179.             else
  1180.                 coroutine.resume(co,unpack(event))
  1181.             end
  1182.         elseif event[1] == "mouse_click" then
  1183.             if event[4] == ofsY + 3 then
  1184.                 for i = 1,#options do
  1185.                     if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then
  1186.                         if options[i] == "ok" then
  1187.                             local test,data = coroutine.resume(co,"return")
  1188.                             return data
  1189.                         elseif options[i] == "cancel" then
  1190.                             return false
  1191.                         end
  1192.                     end
  1193.                 end
  1194.             end
  1195.         end
  1196.     end
  1197. end
  1198.  
  1199. local function dialogBox(title,message,options, h, w)
  1200.     term.setCursorBlink(false)
  1201.     local selected = 1
  1202.     title = title or ""
  1203.     message = message or ""
  1204.     options = options or {}
  1205.     local boxW,boxH = (w or 26), (h or 3)
  1206.     local termX,termY = term.getSize()
  1207.     local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left
  1208.    
  1209.     local space = 0
  1210.     local range = {}
  1211.     for i = 1,#options do
  1212.         range[i] = {s = space,f = space + string.len(options[i])}
  1213.         space = space + string.len(options[i])+3
  1214.     end
  1215.     local ofC = math.ceil((boxW/2)) - math.ceil((space/2))
  1216.    
  1217.     local function drawBox()
  1218.         printC(ofsX,ofsY,"black","blue"," "..title..string.rep(" ",boxW-#title-5).."_[]")
  1219.         term.setBackgroundColor(colors.red)
  1220.         term.setTextColor(colors.white)
  1221.         term.write("X")
  1222.         printC(ofsX,ofsY+1,"black","white",string.sub(" "..message..string.rep(" ",boxW),1,boxW))
  1223.         term.setCursorPos(ofsX,ofsY+2)
  1224.         term.write(string.rep(" ",boxW))
  1225.         term.setCursorPos(ofsX,ofsY+3)
  1226.         term.write(string.rep(" ",boxW))
  1227.         for i = 1,#options do
  1228.             if i == selected then
  1229.                 printC(range[i].s + ofC + ofsX - 1,ofsY + 3,"black","lightGray","["..options[i].."]")
  1230.                 term.setBackgroundColor(colors.white)
  1231.                 term.write(" ")
  1232.             else
  1233.                 term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
  1234.                 term.write(" "..options[i].." ")
  1235.             end
  1236.         end
  1237.         term.setCursorPos(ofsX + ofC + space,ofsY + 3)
  1238.         term.write(string.rep(" ",boxW - (ofC + space)))
  1239.         term.setBackgroundColor(colors.black)
  1240.         term.setTextColor(colors.white)        
  1241.     end
  1242.     while true do
  1243.         drawBox()
  1244.         event = {os.pullEvent()}
  1245.         if event[1] == "key" then
  1246.             if event[2] == 203 then -- left
  1247.                 selected = selected - 1
  1248.                 if selected < 1 then
  1249.                     selected = #options
  1250.                 end
  1251.             elseif event[2] == 205 then -- right
  1252.                 selected = selected + 1
  1253.                 if selected > #options then
  1254.                     selected = 1
  1255.                 end
  1256.             elseif event[2] == 28 then -- enter
  1257.                 return selected , options[selected]
  1258.             end
  1259.         elseif event[1] == "mouse_click" then
  1260.            
  1261.             if bugTest then term.write("M "..event[2].." X "..event[3].." Y "..event[4].."    ") end
  1262.            
  1263.             if event[2] == 1 then
  1264.                 if event[4] == ofsY + 3 then
  1265.                     for i = 1,#options do
  1266.                         if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then
  1267.                             return i , options[i]
  1268.                         end
  1269.                     end
  1270.                 end
  1271.             end
  1272.         end
  1273.     end
  1274. end
  1275.  
  1276. local function rClickMenu(title,tList,posX,posY)
  1277.  
  1278.     term.setCursorBlink(false)
  1279.     local BoxTitle = title
  1280.     local choices = tList
  1281.     local termX,termY = term.getSize()
  1282.     local offX,offY
  1283.    
  1284.     local width = #BoxTitle + 2
  1285.     local hight = #choices + 1
  1286.    
  1287.     for i = 1,#choices do
  1288.         if width < #choices[i] + 2 then
  1289.             width = #choices[i] + 2
  1290.         end
  1291.     end
  1292.    
  1293.     offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))
  1294.    
  1295.     if posX and posY then -- offX,offY = posX,posY
  1296.         if posX >= termX - width - 1 then
  1297.             offX = termX - width - 1
  1298.         else
  1299.             offX = posX
  1300.         end
  1301.         if posY >= termY - hight then
  1302.             offY = termY - hight
  1303.         else
  1304.             offY = posY
  1305.         end
  1306.     end
  1307.    
  1308.     local function reDrawer()
  1309.         printC(offX,offY,colors.black,colors.blue," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1))
  1310.         for i = 1,#choices do
  1311.             printC(offX,offY + i,colors.black,colors.white," "..choices[i]..string.rep(" ",width - #choices[i] - 1))
  1312.         end
  1313.     end
  1314.    
  1315.     while true do
  1316.         reDrawer()
  1317.         local event = {os.pullEvent()}
  1318.         if event[1] == "mouse_click" then
  1319.             if event[2] == 1 then -- event[3] = x event[4] = y
  1320.                 if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then
  1321.                     return choices[event[4] - offY]
  1322.                 else
  1323.                     return
  1324.                 end
  1325.             elseif event[2] == 2 then
  1326.                 return
  1327.             end
  1328.         end
  1329.     end
  1330.    
  1331. end
  1332.  
  1333. local function osRunSpaces(...)
  1334.     clear()
  1335.     if os.newThread then
  1336.         os.newThread(false,...)
  1337.     else
  1338.         return os.run(getfenv(),...)
  1339.     end
  1340. end
  1341.  
  1342. local function fileSelect(mode) -- save_file open_file browse < not yet implemented
  1343.    
  1344.     local title = sTitle.." "..ver
  1345.     local bRun = true
  1346.     local flag = true
  1347.     local clipboard = nil
  1348.     local cut = false
  1349.    
  1350.     local termX,termY = term.getSize()
  1351.     local offsetX,offsetY = 1,1
  1352.     local hight,width = math.ceil(termY-2),math.ceil(termX-2)
  1353.     local oldHight,oldWidth
  1354.    
  1355.     -- offsets
  1356.     local boxOffX,boxOffY = offsetX,offsetY + 2
  1357.     local boxH,boxW = hight - 2 ,width - 2
  1358.    
  1359.     local barX,barY = offsetX + 1,offsetY + 2
  1360.     local barH,barW = 1,width - 1
  1361.    
  1362.     local tbarX,tbarY = offsetX + 1,offsetY + 1
  1363.     local tbarH,tbarW = 1,width - 1
  1364.    
  1365.     local exitX,exitY = offsetX + width - 1 ,offsetY + 1
  1366.    
  1367.     local pading = string.rep(" ",boxW)
  1368.     local path = {dir:match("[^/]+")}
  1369.     local list
  1370.    
  1371.     local fSlash = "/"
  1372.     local listOff = 0
  1373.    
  1374.     local function stringPath() -- compacted this a lot
  1375.         return fSlash..table.concat(path,fSlash)
  1376.     end
  1377.    
  1378.     local sPath
  1379.     local tItemList = {}
  1380.  
  1381.     local function newList()
  1382.         listOff = 0
  1383.         flag = true
  1384.         tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
  1385.         sPath = stringPath()
  1386.         local folders = {}
  1387.         local files = {}
  1388.         local disks = {}
  1389.         if not fs.exists(sPath) then
  1390.             path = {}
  1391.             sPath = stringPath()
  1392.             dialogBox("ERROR:","Path no longer exists",{"ok"})
  1393.         end
  1394.         local test,list = pcall(fs.list,sPath) -- stopes fs.list crash
  1395.         if list == nil then
  1396.             list = {}
  1397.             dialogBox("ERROR : ","fs.list crashed",{"ok"})
  1398.         end
  1399.         if #path == 0 then
  1400.             for i,v in pairs(rs.getSides()) do
  1401.                 if disk.isPresent(v) then
  1402.                     if disk.hasData(v) then
  1403.                         table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
  1404.                         disks[disk.getMountPath(v)] = true
  1405.                     elseif disk.hasAudio(v) then
  1406.                         table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
  1407.                     end
  1408.                 end
  1409.             end
  1410.         end
  1411.         for i,v in pairs(list) do
  1412.             if fs.isDir(sPath..fSlash..v) then
  1413.                 table.insert(folders,v)
  1414.             else
  1415.                 table.insert(files,v)
  1416.             end
  1417.         end
  1418.         table.sort(folders)
  1419.         table.sort(files)
  1420.         for i,v in pairs(folders) do
  1421.             if disks[v] == nil then
  1422.                 table.insert(tItemList,{n = v, id = "folder"})
  1423.             end
  1424.         end
  1425.         for i,v in pairs(files) do
  1426.             table.insert(tItemList,{n = v, id = "file"})
  1427.         end
  1428.     end
  1429.    
  1430.     newList()
  1431.    
  1432.     local tIcons = {
  1433.     back = {tCol = "lightGray",bCol = "blue",txt = " < "},
  1434.     disk = {tCol = "lime",bCol = "green",txt = "[*]"},
  1435.     audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
  1436.     folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
  1437.     file = {tCol = "lime",bCol = "cyan",txt = "   "}}
  1438.    
  1439.     while bRun do
  1440.         if flag then
  1441.             flag = false
  1442.             -- clear
  1443.             if oldHight ~= hight and oldWidth ~= width then
  1444.                 term.setBackgroundColor(colors.black)
  1445.                 term.clear()
  1446.                 oldHight,oldWidth = hight,width
  1447.             end
  1448.             -- draw top title bar
  1449.             term.setCursorPos(tbarX,tbarY)
  1450.             term.setTextColor(colors.black)
  1451.             term.setBackgroundColor(colors.blue)
  1452.             local b = tbarW - #title -2
  1453.             if b < 0 then
  1454.                 b = 0
  1455.             end
  1456.             term.write(string.sub(" "..title,1,tbarW)..string.rep(" ",b))
  1457.             term.setTextColor(colors.white)
  1458.             term.setBackgroundColor(colors.red)
  1459.             term.write("X")
  1460.            
  1461.             -- draw location bar
  1462.             term.setCursorPos(barX,barY)
  1463.             term.setTextColor(colors.black)
  1464.             term.setBackgroundColor(colors.lightGray)
  1465.             local a = barW - #sPath - 1
  1466.             if a < 0 then
  1467.                 a = 0
  1468.             end
  1469.             local tmppath = sPath
  1470.             if shell and shell.getDisplayName then
  1471.                 tmppath = shell.getDisplayName(sPath)
  1472.                 --dialogBox("yay")
  1473.             else
  1474.                 --dialogBox("moop")
  1475.             end
  1476.             tmppath = tmppath or sPath
  1477.             local a = barW - #tmppath - 1
  1478.             if a < 0 then
  1479.                 a = 0
  1480.             end
  1481.             term.write(string.sub(" "..tmppath,1,barW)..string.rep(" ",a))
  1482.            
  1483.             -- draw scroll bar
  1484.             if #tItemList > boxH then
  1485.                 term.setBackgroundColor(colors.lightGray)
  1486.                 for i = 1,boxH do
  1487.                     term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
  1488.                     local scroll = math.floor( boxH* (listOff/(#tItemList-boxH+2)) )+1
  1489.                     if i == scroll then
  1490.                         term.setBackgroundColor(colors.gray)
  1491.                         term.write(" ")
  1492.                         term.setBackgroundColor(colors.lightGray)
  1493.                     else
  1494.                         term.write(" ")
  1495.                     end
  1496.                 end
  1497.             else
  1498.                 term.setBackgroundColor(colors.gray)
  1499.                 for i = 1,boxH do
  1500.                     term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
  1501.                     term.write(" ")
  1502.                 end
  1503.             end
  1504.            
  1505.             -- draw main section
  1506.             term.setTextColor(colors.black)
  1507.             term.setBackgroundColor(colors.cyan)
  1508.             for i = 1,boxH do -- listOff
  1509.                 --term.setCursorPos(1+boxOffX,i+boxOffY)
  1510.                 local sel = i+listOff
  1511.                 if tItemList[sel] then
  1512.                     printC(1+boxOffX,i+boxOffY,colors[tIcons[tItemList[sel].id].tCol],colors[tIcons[tItemList[sel].id].bCol],tIcons[tItemList[sel].id].txt)
  1513.                     printC(4+boxOffX,i+boxOffY,"black","cyan",string.sub(" "..tItemList[sel].n..pading,1,boxW-3))
  1514.                 else
  1515.                     printC(1+boxOffX,i+boxOffY,"black","cyan",pading)
  1516.                 end
  1517.             end
  1518.             term.setTextColor(colors.white)
  1519.             term.setBackgroundColor(colors.black)
  1520.            
  1521.             if bugTest then
  1522.                 term.setCursorPos(1,1)
  1523.                 term.write(listOff.." "..boxOffY.." "..boxH)
  1524.             end
  1525.            
  1526.         end
  1527.        
  1528.         -- react to events
  1529.         local event = {os.pullEvent()}
  1530.        
  1531.         if event[1] == "mouse_click" then
  1532.             if event[2] == 1 then -- left mouse
  1533.                 local temp = nil
  1534.                 if event[4] > boxOffY and event[4] <= boxH + boxOffY then
  1535.                     temp = tItemList[event[4]+listOff-boxOffY]
  1536.                 end
  1537.                 if temp and event[3] > boxOffX and event[3] <= #temp.n + 4 + boxOffX and event[3] < boxOffX + boxW then
  1538.                     if temp.id == "back" then
  1539.                         table.remove(path,#path)
  1540.                         newList()
  1541.                     elseif temp.id == "folder" or temp.id == "disk" then
  1542.                         table.insert(path,temp.n)
  1543.                         newList()
  1544.                     elseif temp.id == "file" then
  1545.                         if dialogBox("Run file ?",temp.n,{"yes","no"}) == 1 then
  1546.                             local test,info = osRunSpaces(stringPath()..fSlash..temp.n)
  1547.                             term.setCursorBlink(false)
  1548.                             if not test then
  1549.                                 dialogBox("ERROR",tostring(info),{"ok"})
  1550.                             end
  1551.                         end
  1552.                         flag = true
  1553.                     end
  1554.                 elseif event[3] == boxOffX+boxW+1 and event[4] > boxOffY and event[4] <= boxOffY+boxH then
  1555.                     if #tItemList > boxH then
  1556.                         if event[4] == boxOffY + 1 then
  1557.                             listOff = 0
  1558.                         elseif event[4] == boxOffY+boxH then
  1559.                             listOff = #tItemList + 1 - boxH
  1560.                         else
  1561.                             listOff = math.ceil((event[4] - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH)))
  1562.                         end
  1563.                         flag = true
  1564.                     end
  1565.                 elseif event[3] == exitX and event[4] == exitY then
  1566.                     if dialogBox("Confirm","Exit application",{"yes","no"}) == 1 then
  1567.                         bRun = false
  1568.                     end
  1569.                     flag = true
  1570.                 end
  1571.             elseif event[2] == 2 then -- right mouse
  1572.                 local temp = nil
  1573.                 local sChoice = nil
  1574.                
  1575.                 if event[4] > boxOffY and event[4] <= boxH + boxOffY then
  1576.                     temp = tItemList[event[4]+listOff-boxOffY]
  1577.                 end
  1578.                
  1579.                 -- moved
  1580.                 local paste
  1581.                 if clipboard then
  1582.                     paste = "Paste"
  1583.                 end
  1584.                
  1585.                 if temp and event[3] > boxOffX and event[3] <= #temp.n + 4 + boxOffX and event[3] < boxOffX + boxW then
  1586.                    
  1587.                     if temp.id == "disk" then
  1588.                         sChoice = rClickMenu("Options",{"Open","Copy","Eject","ID label","Set label","Clear label"},event[3]+1,event[4]+1)
  1589.                     elseif temp.id == "folder" then
  1590.                         sChoice = rClickMenu("Options",{"Open","Copy","Delete"},event[3]+1,event[4]+1)
  1591.                     elseif temp.id == "file" then
  1592.                         sChoice = rClickMenu("Options",{"Run","Open With","Rename","Delete", "Cut", "Copy", paste},event[3]+1,event[4]+1)
  1593.                     elseif temp.id == "audio" then
  1594.                         sChoice = rClickMenu("Options",{"Play","Eject"},event[3]+1,event[4]+1)
  1595.                     end
  1596.                    
  1597.                 else
  1598.                     if event[3] > boxOffX and event[3] <= 5 + boxOffX and event[3] < boxOffX + boxW then
  1599.                         if event[4] > offsetY and event[4] < hight + offsetY then
  1600.                             sChoice = rClickMenu("Options",{"New File","New Folder", paste},event[3]+1,event[4]+1)
  1601.                         end
  1602.                     else
  1603.                         table.remove(path,#path)
  1604.                         newList()
  1605.                     end
  1606.                 end
  1607.                 if sChoice == "Open With" then
  1608.                     sChoice = rClickMenu("Options",{"Edit","Paint"},event[3]+12,event[4]+1)
  1609.                 elseif sChoice == "Run" then
  1610.                     local runWin
  1611.                     if windowDimensions then
  1612.                         runWin = "Run win"
  1613.                     end
  1614.                     sChoice = rClickMenu("Options",{"Run","Run CMD","Debug",runWin},event[3]+12,event[4]+1)
  1615.                 end
  1616.                 if sChoice == "Run win" and windowDimensions then -- choice execution
  1617.                     osRunSpaces("start",stringPath()..fSlash..temp.n) -- might be a probblem -- shell
  1618.                     flag = true
  1619.                 elseif sChoice == "Play" then
  1620.                     disk.playAudio(temp.s)
  1621.                 elseif sChoice == "ID label" then
  1622.                     dialogBox("ID label",disk.getDiskID(temp.s).." "..tostring(disk.getLabel(temp.s)),{"ok"})
  1623.                 elseif sChoice == "Set label" then
  1624.                     local name = InputBox("Label?")
  1625.                     if name then
  1626.                         disk.setLabel(temp.s,name)
  1627.                     end
  1628.                 elseif sChoice == "Clear label" then -- dialogBox(
  1629.                     if dialogBox("Confirm","Cleal Label from "..temp.s,{"yes","no"}) == 1 then
  1630.                         disk.setLabel(temp.s)
  1631.                     end
  1632.                 --[[
  1633.                 elseif sChoice == "CHIP 8" then -- this was a temp hackin will be going
  1634.                     local function openDevice(sType)
  1635.                         for i,v in pairs(rs.getSides()) do
  1636.                             if peripheral.isPresent(v) and peripheral.getType(v) == sType then
  1637.                                 return peripheral.wrap(v),v
  1638.                             end
  1639.                         end
  1640.                     end
  1641.                     local func,side = openDevice("monitor")
  1642.                     osRunSpaces("chip8",stringPath()..fSlash..temp,side)
  1643.                     ]]--
  1644.                 elseif sChoice == "New File" then -- experemntal
  1645.                     local name = InputBox()
  1646.                     if name then
  1647.                         if fs.exists(stringPath()..fSlash..name) then
  1648.                             dialogBox("ERROR","Name exists",{"ok"})
  1649.                         else
  1650.                             local file = fs.open(stringPath()..fSlash..name,"w")
  1651.                             if file then
  1652.                                 file.write("")
  1653.                                 file.close()
  1654.                                 newList()
  1655.                             else
  1656.                                 dialogBox("ERROR","File not created",{"ok"})
  1657.                             end
  1658.                         end
  1659.                     end
  1660.                 elseif sChoice == "New Folder" then -- experemental
  1661.                     local name = InputBox()
  1662.                     if name then
  1663.                         if fs.exists(stringPath()..fSlash..name) then
  1664.                             dialogBox("ERROR","Name exists",{"ok"})
  1665.                         else
  1666.                             if pcall(fs.makeDir,stringPath()..fSlash..name) then
  1667.                                 newList()
  1668.                             else
  1669.                                 dialogBox("ERROR","Access Denied",{"ok"})
  1670.                             end
  1671.                         end
  1672.                     end
  1673.                 elseif sChoice == "Open" then
  1674.                     table.insert(path,temp.n)
  1675.                     newList()
  1676.                 elseif sChoice == "Run" then
  1677.                     local test,info = osRunSpaces(stringPath()..fSlash..temp.n)
  1678.                     term.setCursorBlink(false)
  1679.                     if not test then
  1680.                         dialogBox("ERROR",tostring(info),{"ok"})
  1681.                     end
  1682.                 elseif sChoice == "Run CMD" or sChoice == "Debug" then
  1683.                     local cmd = InputBox("Commands")
  1684.                     if cmd then
  1685.                         local test,info = osRunSpaces(stringPath()..fSlash..temp.n,unpack(fixArgs(cmd)))
  1686.                         term.setCursorBlink(false)
  1687.                         if not test then
  1688.                             dialogBox("ERROR",tostring(info),{"ok"})
  1689.                         else
  1690.                             if sChoice == "Debug" then
  1691.                                 term.setCursorBlink(false)
  1692.                                 os.pullEvent("key")
  1693.                             end
  1694.                         end
  1695.                     end
  1696.                 elseif sChoice == "Edit" then
  1697.                     if temp.id == "file" then
  1698.                         osRunSpaces("/rom/programs/edit",stringPath()..fSlash..temp.n)
  1699.                     else
  1700.                         dialogBox("ERROR","Can't edit a Folder",{"ok"})
  1701.                     end
  1702.                 elseif sChoice == "Delete" then
  1703.                     if dialogBox("Confirm","Delete "..temp.id.." "..temp.n,{"yes","no"}) == 1 then
  1704.                         if fs.isReadOnly(stringPath()..fSlash..temp.n) then
  1705.                             dialogBox("ERROR",temp.id.." Is read Only",{"ok"})
  1706.                         else
  1707.                             fs.delete(stringPath()..fSlash..temp.n)
  1708.                             newList()
  1709.                         end
  1710.                     end
  1711.                 elseif sChoice == "Paint" then
  1712.                     if temp.id == "file" then
  1713.                         osRunSpaces("/rom/programs/color/paint",stringPath()..fSlash..temp.n)
  1714.                     else
  1715.                         dialogBox("ERROR","Can't edit a Folder",{"ok"})
  1716.                     end
  1717.                 elseif sChoice == "Eject" then
  1718.                     if dialogBox("Confirm","Eject disk "..temp.s.." "..fSlash..temp.n,{"yes","no"}) == 1 then
  1719.                         disk.eject(temp.s)
  1720.                         newList()
  1721.                     end
  1722.                 elseif sChoice == "Copy" then
  1723.                     clipboard = {stringPath(), temp.n}
  1724.                     cut = false
  1725.                 elseif sChoice == "Cut" then
  1726.                     clipboard = {stringPath(), temp.n}
  1727.                     cut = true
  1728.                 elseif sChoice == "Paste" then
  1729.                     if cut then
  1730.                         local s, m = pcall(function()
  1731.                             fs.move(clipboard, stringPath().."/"..temp.n)
  1732.                             cut = false
  1733.                             clipboard = nil
  1734.                         end)
  1735.                         if not s then
  1736.                             dialogBox("Error", (m or "Couldn't move"), {"ok"}, 4, 30)
  1737.                         end
  1738.                         if bugTest then
  1739.                             local x, y = term.getCursorPos()
  1740.                             term.setCursorPos(1, ({term.getSize()})[2])
  1741.                             write("from "..clipboard[1].."/"..clipboard[2].." to "..stringPath().."/"..clipboard[2])
  1742.                         end
  1743.                     else
  1744.                         local s, m = pcall(function()
  1745.                             fs.copy(clipboard[1].."/"..clipboard[2], stringPath().."/"..clipboard[2])
  1746.                         end)
  1747.                         if not s then
  1748.                             dialogBox("Error", (m or "Couldn't copy"), {"ok"}, 4, 30)
  1749.                         end
  1750.                         if bugTest then
  1751.                             local x, y = term.getCursorPos()
  1752.                             term.setCursorPos(1, ({term.getSize()})[2])
  1753.                             write("from "..clipboard[1].."/"..clipboard[2].." to "..stringPath().."/"..clipboard[2])
  1754.                         end
  1755.                     end
  1756.                     newList()
  1757.                 elseif sChoice == "Rename" then -- new parts of the above thanks kilo
  1758.                     local sName = InputBox("New Name")
  1759.                     if type(sName) == "string" and sName ~= "" then
  1760.                         local s, m = pcall(function()
  1761.                             fs.move(stringPath()..fSlash..temp.n,stringPath()..fSlash..sName)
  1762.                         end)
  1763.                         if not s then
  1764.                             dialogBox("Error", (m or "Rename failed"), {"ok"})
  1765.                         end
  1766.                     end
  1767.                     newList()
  1768.                 end
  1769.                 flag = true
  1770.             end
  1771.         elseif event[1] == "mouse_scroll" then -- flag this needs new math
  1772.             local old = listOff
  1773.             listOff = listOff + event[2]
  1774.             if listOff < 0 then
  1775.                 listOff = 0
  1776.             end
  1777.             if #tItemList + 1 - boxH > 0 and listOff > #tItemList + 1 - boxH then
  1778.                 listOff = #tItemList + 1 - boxH
  1779.             elseif listOff > 0 and #tItemList + 1 - boxH < 0 then
  1780.                 listOff = 0
  1781.             end
  1782.             if listOff ~= old then
  1783.                 flag = true
  1784.             end
  1785.        
  1786.         elseif event[1] == "mouse_drag" then -- test
  1787.             if event[3] == boxOffX+boxW+1 and event[4] > boxOffY and event[4] <= boxOffY+boxH then
  1788.                 if #tItemList > boxH then
  1789.                     if event[4] == boxOffY + 1 then
  1790.                         listOff = 0
  1791.                     elseif event[4] == boxOffY+boxH then
  1792.                         listOff = #tItemList + 1 - boxH
  1793.                     else
  1794.                         listOff = math.ceil((event[4] - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH)))
  1795.                     end
  1796.                     flag = true
  1797.                 end
  1798.             end
  1799.            
  1800.         elseif event[1] == "disk" or event[1] == "disk_eject" then
  1801.             newList()
  1802.         elseif event[1] == "window_resize" then
  1803.             termX,termY = term.getSize()
  1804.             offsetX,offsetY = 1,1
  1805.             hight,width = math.ceil(termY-2),math.ceil(termX-2)
  1806.            
  1807.             boxOffX,boxOffY = offsetX,offsetY + 2
  1808.             boxH,boxW = hight - 2 ,width - 2
  1809.            
  1810.             barX,barY = offsetX + 1,offsetY + 2
  1811.             barH,barW = 1,width - 1
  1812.            
  1813.             tbarX,tbarY = offsetX + 1,offsetY + 1
  1814.             tbarH,tbarW = 1,width - 1
  1815.            
  1816.             exitX,exitY = offsetX + width - 1 ,offsetY + 1
  1817.             pading = string.rep(" ",boxW)
  1818.            
  1819.             flag = true
  1820.         elseif event[1] == "redraw" then
  1821.             flag = true
  1822.         end
  1823.     end
  1824. end
  1825. local function main()
  1826.     if term.isColor() then
  1827.         clear()
  1828.         fileSelect()
  1829.         clear()
  1830.     else
  1831.         error("Not an Advanced Computer (gold) ")
  1832.     end
  1833. end
  1834. local trash = (norun or main())]==]
  1835. local file4path = "//SYS_MOUSE/programs/MouseFB.lua"
  1836. local file = fs.open(file4path,"w")
  1837. file.write(file4)
  1838. file.close()
  1839. local file5 = [==[--[[
  1840.         method decovery
  1841.         by BigSHinyToys
  1842. ]]--
  1843.  
  1844. local tab = 1
  1845. local tSide = rs.getSides()
  1846. local width,hight = term.getSize()
  1847. local space = math.floor(width/6)
  1848. local methods = {}
  1849.  
  1850. local function clear()
  1851.     term.setBackgroundColor(colors.black)
  1852.     term.setTextColor(colors.white)
  1853.     term.clear()
  1854.     term.setCursorBlink(false)
  1855.     term.setCursorPos(1,1)
  1856. end
  1857.  
  1858. local function clearL(y)
  1859.     term.setCursorPos(1,y)
  1860.     term.clearLine()
  1861. end
  1862.  
  1863. local function clearBox(backCol)
  1864.     term.setBackgroundColor(colors[backCol])
  1865.     for i = 2,hight do
  1866.         clearL(i)
  1867.     end
  1868. end
  1869.  
  1870. local function setCol(textCol,backCol)
  1871.     term.setTextColor(colors[textCol])
  1872.     term.setBackgroundColor(colors[backCol])
  1873. end
  1874.  
  1875. local function printC(posX,posY,textCol,backCol,text)
  1876.     term.setCursorPos(posX,posY)
  1877.     term.setTextColor(colors[textCol])
  1878.     term.setBackgroundColor(colors[backCol])
  1879.     term.write(text)
  1880. end
  1881.  
  1882. local function drawTabs()
  1883.     for i = 1,6 do
  1884.         if i == tab then
  1885.             printC((space*(i-1))+1,1,"green","lime","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
  1886.         else
  1887.             printC((space*(i-1))+1,1,"blue","lightBlue","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
  1888.         end
  1889.     end
  1890.     printC(width,1,"white","red","X")
  1891. end
  1892.  
  1893. local function drawData()
  1894.     if peripheral.isPresent(tSide[tab]) then
  1895.         local pos = 3
  1896.         printC(1,2,"green","lime","Peripheral : "..peripheral.getType(tSide[tab]))
  1897.         methods = peripheral.getMethods(tSide[tab])
  1898.         for i,v in pairs(methods) do
  1899.             printC(1,pos,"green","lime",tostring(i).." "..tostring(v))
  1900.             pos = pos + 1
  1901.         end
  1902.     else
  1903.         printC(1,2,"green","lime","Peripheral : NIL")
  1904.         methods = {}
  1905.     end
  1906. end
  1907.  
  1908. clear()
  1909. local lastTab
  1910.  
  1911. local function draw()
  1912.     clearBox("lime")
  1913.     drawTabs()
  1914.     drawData()
  1915.     lastTab = tab
  1916. end
  1917.  
  1918. while true do
  1919.     if lastTab ~= tab then
  1920.         draw()
  1921.     end
  1922.     local event = {os.pullEvent()}
  1923.     if event[1] == "mouse_click" then
  1924.         if event[2] == 1 then -- left click
  1925.             if event[4] == 1 then -- first line
  1926.                 for i = 1,6 do
  1927.                     if event[3] > space*(i-1) and event[3] < (space*(i))+1 then
  1928.                         tab = i
  1929.                     end
  1930.                 end
  1931.                 if event[3] == width then
  1932.                     break
  1933.                 end
  1934.             elseif methods[event[4] - 2] and type(methods[event[4] - 2]) == "string" and event[3] < string.len(methods[event[4]-2])+string.len(tostring(event[4] - 2))+1 then
  1935.                 draw()
  1936.                 local test = {pcall(peripheral.call,tSide[tab],methods[event[4] - 2])}
  1937.                 term.setCursorPos(1,hight - 1)
  1938.                 setCol("red","lightBlue")
  1939.                 write(tostring(methods[event[4] - 2]).." ")
  1940.                 for i = 1,#test do
  1941.                     write(tostring(test[i]).." ")
  1942.                 end
  1943.             end
  1944.         end
  1945.     elseif event[1] == "peripheral" or event[1] == "peripheral_detach" then
  1946.         lastTab = nil
  1947.     end
  1948. end
  1949. clear()]==]
  1950. local file5path = "//SYS_MOUSE/programs/TUImethod.lua"
  1951. local file = fs.open(file5path,"w")
  1952. file.write(file5)
  1953. file.close()
  1954. local file6 = [==[--[[
  1955.         desktop
  1956.         by BigSHinyToys
  1957. ]]--
  1958.  
  1959. local ver = "ALPHA"
  1960. local positions = {}
  1961. local lastClick = false
  1962. local clickTimer
  1963. local lastObject
  1964. local icons = {}
  1965. local startBGColor = "cyan"
  1966. local startTColor = "blue"
  1967. local taskBarColor = "lightBlue"
  1968. local doubleClickTime = 0.5
  1969. local termX,termY = term.getSize()
  1970. local user
  1971. local timeUpdate
  1972. local redNet = false
  1973.  
  1974.  
  1975. local function clear()
  1976.     term.setBackgroundColor(colors.black)
  1977.     term.setTextColor(colors.white)
  1978.     term.clear()
  1979.     term.setCursorBlink(false)
  1980.     term.setCursorPos(1,1)
  1981. end
  1982.  
  1983. local function tag(this)
  1984.     print(this)
  1985.     os.pullEvent()
  1986. end
  1987.  
  1988. local function colorSet(textColor,backColor)
  1989.     term.setTextColor(colors[textColor])
  1990.     term.setBackgroundColor(colors[backColor])
  1991. end
  1992.  
  1993. local function openDevice(sType)
  1994.     for i,v in pairs(rs.getSides()) do
  1995.         if peripheral.isPresent(v) and peripheral.getType(v) == sType then
  1996.             return peripheral.wrap(v),v
  1997.         end
  1998.     end
  1999. end
  2000.  
  2001. local function printC(posX,posY,textCol,backCol,text)
  2002.     term.setCursorPos(posX,posY)
  2003.     colorSet(textCol,backCol)
  2004.     term.write(text)
  2005. end
  2006.  
  2007. local function isObject(hereX,hereY) -- lx left X rx right X ty top Y by bottom Y
  2008.     for i,v in pairs(positions) do
  2009.         if hereX >= v.lx and hereX <= v.rx and hereY >= v.ty and hereY <= v.by then
  2010.             return i
  2011.         end
  2012.     end
  2013. end
  2014.  
  2015. local function runObject(num)
  2016.     clear()
  2017.     positions[num].func()
  2018. end
  2019.  
  2020. local function newObject(leftX,rightX,topY,bottomY,thisFunct)
  2021.     table.insert(positions,{lx = leftX,rx = rightX,ty = topY,by = bottomY,func = thisFunct})
  2022.     return #positions
  2023. end
  2024.  
  2025. local function runProg(...)
  2026.     term.setBackgroundColor(colors.black)
  2027.     term.setTextColor(colors.white)
  2028.     if os.newThread then
  2029.         return os.newThread(false,...)
  2030.     else
  2031.         return os.run(getfenv(),...)
  2032.     end
  2033. end
  2034.  
  2035. local function newIcon(posX,posY,name,file)
  2036.     table.insert(icons,{X = posX,Y = posY,label = name,link = file,object = newObject(posX,posX+3,posY,posY+3,function() return runProg(file) end)})
  2037. end
  2038.  
  2039. local function updateIcons()
  2040.     for i,v in pairs(icons) do
  2041.         v.X = positions[v.object].lx
  2042.         v.Y = positions[v.object].ty
  2043.     end
  2044. end
  2045.  
  2046. colorSet("white","black")
  2047. term.clear()
  2048. term.setCursorPos(1,1)
  2049.  
  2050. local function reDraw()
  2051.     colorSet("white","black")
  2052.     term.clear()
  2053.     updateIcons()
  2054.     printC(1,termY,startTColor,startBGColor,"[START]")
  2055.     printC(8,termY,"white",taskBarColor,string.rep(" ",termX-7))
  2056.     for i,v in pairs(icons) do
  2057.         printC(v.X,v.Y,"black","white","    ")
  2058.         printC(v.X,v.Y+1,"black","white","    ")
  2059.         printC(v.X,v.Y+2,"black","white","    ")
  2060.         printC(v.X,v.Y+3,"black","white",v.label)
  2061.     end
  2062.     local sTime = textutils.formatTime(os.time())
  2063.     if #sTime ~= 8 then
  2064.         sTime = " "..sTime
  2065.     end
  2066.     printC(termX - 7 ,termY,"white","blue",sTime)
  2067.     timeUpdate = os.startTimer(1)
  2068.     if redNet then
  2069.         printC(termX - 12 ,termY,"white","blue"," {(c ")
  2070.     else
  2071.         printC(termX - 12 ,termY,"red","blue"," {(c ")
  2072.     end
  2073.     os.queueEvent("redraw")
  2074. end
  2075.  
  2076. local function moveObject(object,posX,posY)
  2077.     local sizeX = positions[object].rx - positions[object].lx
  2078.     local sizeY = positions[object].by - positions[object].ty
  2079.     --print(sizeX.." "..sizeY)
  2080.     os.pullEvent()
  2081.     positions[object].lx = posX
  2082.     positions[object].rx = posX + sizeX
  2083.     positions[object].ty = posY
  2084.     positions[object].by = posY + sizeY
  2085.     reDraw()
  2086. end
  2087.  
  2088. local function rClickMenu(title,tList,posX,posY)
  2089.  
  2090.     term.setCursorBlink(false)
  2091.     local BoxTitle = title
  2092.     local choices = tList
  2093.     local termX,termY = term.getSize()
  2094.     local offX,offY
  2095.    
  2096.     local width = #BoxTitle + 2
  2097.     local hight = #choices + 1
  2098.    
  2099.     for i = 1,#choices do
  2100.         if width < #choices[i] + 2 then
  2101.             width = #choices[i] + 2
  2102.         end
  2103.     end
  2104.    
  2105.     offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))
  2106.    
  2107.     if posX and posY then -- offX,offY = posX,posY
  2108.         if posX >= termX - width - 1 then
  2109.             offX = termX - width - 1
  2110.         else
  2111.             offX = posX
  2112.         end
  2113.         if posY >= termY - hight then
  2114.             offY = termY - hight
  2115.         else
  2116.             offY = posY
  2117.         end
  2118.     end
  2119.    
  2120.     local function reDrawer()
  2121.         printC(offX,offY,"black","blue"," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1))
  2122.         for i = 1,#choices do
  2123.             printC(offX,offY + i,"black","white"," "..choices[i]..string.rep(" ",width - #choices[i] - 1))
  2124.         end
  2125.     end
  2126.    
  2127.     while true do
  2128.         reDrawer()
  2129.         local event = {os.pullEvent()}
  2130.         if event[1] == "mouse_click" then
  2131.             if event[2] == 1 then -- event[3] = x event[4] = y
  2132.                 if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then
  2133.                     return choices[event[4] - offY]
  2134.                 else
  2135.                     return
  2136.                 end
  2137.             elseif event[2] == 2 then
  2138.                 return
  2139.             end
  2140.         end
  2141.     end
  2142. end
  2143.  
  2144. local tUser = {
  2145.     admin = "",
  2146.     ted = "random"
  2147.     }
  2148.  
  2149. local img = [[                                  555 111
  2150.                eeeee    eeeeee    555 111
  2151.               ee   ee  ee    ee   555 111
  2152.               e     e  e
  2153.               e     e  ee         eee 222
  2154.    ccc cc cc ccc    e   eeeeee    eee 222
  2155.    c    c c  ce c   e        ee b eee 222 b
  2156.    cc    c   ceec  ee         eb b b  bb b b
  2157.    c    c c  ccceeee   ee    eebbb b  bb bbb
  2158.    ccc cc cc c          eeeeee b b bb b  b b]]
  2159.  
  2160. local function makeDraw(pic)
  2161.     local hex = {"a","b","c","d","e","f"}
  2162.     local n = {}
  2163.     n["0"] = 1
  2164.     for i = 1,9 do
  2165.         n[tostring(i)] = 2^(i)
  2166.     end
  2167.     for i = 10,15 do
  2168.         n[hex[i-9]] = 2^(i)
  2169.     end
  2170.     local tWords = {}
  2171.     for match in string.gmatch(pic, "[^\n]+" ) do
  2172.         table.insert( tWords, match )
  2173.     end
  2174.     return function()
  2175.         local lines = tWords
  2176.         local hex = n
  2177.         local termX,termY = term.getCursorPos()
  2178.         for i = 1,#lines do
  2179.             for b = 1,#lines[i] do
  2180.                 local this = string.sub(lines[i],b,b)
  2181.                 if this ~= " " then
  2182.                     term.setCursorPos(b,i)
  2183.                     term.setBackgroundColor(hex[this])
  2184.                     term.write(" ")
  2185.                 end
  2186.             end
  2187.         end
  2188.     end
  2189. end
  2190.  
  2191. local drawImg = makeDraw(img)
  2192.  
  2193. local function loginScreen()
  2194.     local oldPullEvent = os.pullEvent
  2195.     os.pullEvent = os.pullEventRaw
  2196.    
  2197.     local flag = false
  2198.  
  2199.     while true do
  2200.         colorSet("red","lightBlue")
  2201.         term.clear()
  2202.         term.setCursorPos(1,1)
  2203.         drawImg()
  2204.         colorSet("red","lightBlue")
  2205.         if flag then
  2206.             term.setCursorPos(1,1)
  2207.             write("ERROR : Access Denied")
  2208.         end
  2209.         term.setCursorPos(1,termY-2)
  2210.         write("User     : ")
  2211.         local sUser = read()
  2212.         term.setCursorPos(1,termY-1)
  2213.         write("Password : ")
  2214.         local pass = read("*")
  2215.         if tUser[sUser] and tUser[sUser] == pass then
  2216.             print("access Granted")
  2217.             user = sUser
  2218.             break
  2219.         else
  2220.             flag = true
  2221.         end
  2222.     end
  2223.     os.pullEvent = oldPullEvent
  2224. end
  2225.  
  2226. newIcon(2,2,"FILE","SYS_MOUSE/programs/MouseFB.lua")
  2227. newIcon(8,2,"BENC","SYS_MOUSE/programs/Bench.lua")
  2228. newIcon(14,2,"HARD","SYS_MOUSE/programs/TUImethod.lua")
  2229.  
  2230. local wrap,sideWIFI = openDevice("modem")
  2231. if sideWIFI then
  2232.     rednet.open(sideWIFI)
  2233.     redNet = true
  2234. else
  2235.     redNet = false
  2236. end
  2237.  
  2238. local function deskTop()
  2239.     timeUpdate = os.startTimer(1)
  2240.     clear()
  2241.     reDraw()
  2242.     while true do
  2243.         local event = {os.pullEvent()}
  2244.         if event[1] == "timer" and event[2] == clickTimer then
  2245.             lastClick = false
  2246.         elseif event[1] == "mouse_click" then
  2247.             if event[2] == 1 and lastClick then -- doubble left click
  2248.                 if lastObject ~= nil and lastObject == isObject(event[3],event[4]) then
  2249.                     runObject(lastObject)
  2250.                     timeUpdate = os.startTimer(1)
  2251.                     reDraw()
  2252.                     lastClick = false
  2253.                     clickTimer = nil
  2254.                 end
  2255.             elseif event[2] == 1 then -- left click
  2256.                 if event[3] <= 7 and event[4] == termY then
  2257.                     local sChoice = rClickMenu(user,{"programs","Log off","Shutdown","Reboot"},1,termY)
  2258.                     if sChoice == "programs" then
  2259.                         local tList = fs.list("SYS_MOUSE/programs")
  2260.                         local sProgram = rClickMenu("Programs",tList,11,termY)
  2261.                         if sProgram then
  2262.                             clear()
  2263.                             runProg("SYS_MOUSE/programs/"..sProgram)
  2264.                             timeUpdate = os.startTimer(1)
  2265.                         end
  2266.                     elseif sChoice == "Shutdown" then
  2267.                         os.shutdown()
  2268.                     elseif sChoice == "Reboot" then
  2269.                         os.reboot()
  2270.                     elseif sChoice == "Log off" then
  2271.                         break
  2272.                     end
  2273.                     reDraw()
  2274.                 else
  2275.                     clickTimer = os.startTimer(doubleClickTime)
  2276.                     lastClick = true
  2277.                     lastObject = isObject(event[3],event[4])
  2278.                 end
  2279.             elseif event[2] == 2 then -- right click
  2280.                 lastObject = nil
  2281.             elseif event[2] == 3 then -- scroll wheel
  2282.                 lastObject = nil
  2283.                 -- runObject(isObject(event[3],event[4]))
  2284.             end
  2285.         elseif event[1] == "mouse_drag" then
  2286.             if event[2] == 1 then
  2287.                 if lastObject then
  2288.                     moveObject(lastObject,event[3],event[4])
  2289.                     lastClick = false
  2290.                     clickTimer = nil
  2291.                 end
  2292.             end
  2293.         elseif event[1] == "timer" then
  2294.             if event[2] == timeUpdate then
  2295.                 local sTime = textutils.formatTime(os.time())
  2296.                 if #sTime ~= 8 then
  2297.                     sTime = " "..sTime
  2298.                 end
  2299.                 printC(termX - 7 ,termY,"white","blue",sTime)
  2300.                 timeUpdate = os.startTimer(1)
  2301.             end
  2302.         elseif event[1] == "peripheral_detach" or event[1] == "peripheral"  then
  2303.             local wrap,sideWIFI = openDevice("modem")
  2304.             if sideWIFI then
  2305.                 rednet.open(sideWIFI)
  2306.                 redNet = true
  2307.             else
  2308.                 redNet = false
  2309.             end
  2310.             reDraw()
  2311.         end
  2312.     end
  2313. end
  2314.  
  2315. while true do
  2316.     while true do
  2317.         loginScreen()
  2318.         deskTop()
  2319.     end
  2320. end]==]
  2321. local file6path = "//SYS_MOUSE/shell.lua"
  2322. local file = fs.open(file6path,"w")
  2323. file.write(file6)
  2324. file.close()
  2325. local file7 = [==[--[[
  2326.         splitter
  2327.         by BigSHinyToys
  2328. ]]--
  2329. local tArgs = {...}
  2330. local sSide = {}
  2331. for i,v in pairs(rs.getSides()) do
  2332.     sSide[v] = true
  2333. end
  2334. local monSide
  2335. local monBig = false
  2336. local termX,termY = term.getSize()
  2337. local customTerm = {}
  2338. --  local moniter
  2339. local oldMon = {}
  2340. local rmtserv = false
  2341. local sendID
  2342. local client
  2343.  
  2344. local function openDevice(sType)
  2345.     for i,v in pairs(rs.getSides()) do
  2346.         if peripheral.isPresent(v) and peripheral.getType(v) == sType then
  2347.             return peripheral.wrap(v),v
  2348.         end
  2349.     end
  2350. end
  2351.  
  2352. if #tArgs == 1 then
  2353.     if sSide[tArgs[1]] then
  2354.         monSide = string.lower(tArgs[1])
  2355.         if peripheral.isPresent(monSide) and peripheral.getType(monSide) == "monitor" then
  2356.             peripheral.call(monSide,"setTextScale",1)
  2357.             local monX,monY = peripheral.call(monSide,"getSize")
  2358.             if monX >= termX and monY >= termY then
  2359.                 monBig = true
  2360.             else
  2361.                 peripheral.call(monSide,"setTextScale",0.5)
  2362.                 monX,monY = peripheral.call(monSide,"getSize")
  2363.                 if monX >= termX and monY >= termY then
  2364.                     monBig = true
  2365.                 else
  2366.                     print("Monitor to small")
  2367.                 end
  2368.             end
  2369.         end
  2370.     elseif string.lower(tArgs[1]) == "restore" then
  2371.         term.restore()
  2372.     end
  2373. elseif #tArgs == 2 then
  2374.     if string.lower(tArgs[1]) == "server" then -- sendID
  2375.         local device,side = openDevice("modem")
  2376.         if side then
  2377.             client = tonumber(tArgs[2])
  2378.             if client then
  2379.                 rednet.open(side)
  2380.                 rmtserv = true
  2381.             end
  2382.         end
  2383.     elseif string.lower(tArgs[1]) == "client" then
  2384.         sendID = tonumber(tArgs[2])
  2385.         if sendID then
  2386.             local device,side = openDevice("modem")
  2387.             if side then
  2388.                 rednet.open(side)
  2389.                 rmtsend = true
  2390.             end
  2391.         end
  2392.     end
  2393. else
  2394.     print("USAGE: <side> or \"restore\" ")
  2395. end
  2396.  
  2397. local function wrap( _sFunction )
  2398.     return function( ... )
  2399.         peripheral.call(monSide,_sFunction,...)
  2400.         return oldMon[_sFunction](...)
  2401.     end
  2402. end
  2403.  
  2404. local function wrapSend( _sFunction )
  2405.     return function( ... )
  2406.         rednet.send(sendID,textutils.serialize({_sFunction,...}))
  2407.         return oldMon[_sFunction](...)
  2408.     end
  2409. end
  2410.  
  2411. if monBig then
  2412.     --  moniter = peripheral.wrap(monSide)
  2413.     for k,v in pairs(term.native) do
  2414.         oldMon[k] = v
  2415.     end
  2416.     for k,v in pairs( term.native ) do
  2417.         if type( k ) == "string" and type( v ) == "function" then
  2418.             customTerm[k] = wrap(k)
  2419.         end
  2420.     end
  2421.     term.redirect(customTerm)
  2422.     term.clear()
  2423.     term.setCursorPos(1,1)
  2424.     print("Running on monitor")
  2425. elseif rmtsend then
  2426.     for k,v in pairs(term.native) do
  2427.         oldMon[k] = v
  2428.     end
  2429.     for k,v in pairs( term.native ) do
  2430.         if type( k ) == "string" and type( v ) == "function" then
  2431.             customTerm[k] = wrapSend(k)
  2432.         end
  2433.     end
  2434.     term.redirect(customTerm)
  2435.     term.clear()
  2436.     term.setCursorPos(1,1)
  2437.     print("Running on monitor")
  2438. elseif rmtserv then
  2439.     term.clear()
  2440.     term.setCursorPos(1,1)
  2441.     print("Running on monitor")
  2442.     while true do
  2443.         local event,senderID,mes,dist = os.pullEvent()
  2444.         if event == "rednet_message" and senderID == client then
  2445.             local this = textutils.unserialize(mes)
  2446.             local ins = this[1]
  2447.             table.remove(this,1)
  2448.             term[ins](unpack(this))
  2449.         end
  2450.     end
  2451. end]==]
  2452. local file7path = "//SYS_MOUSE/split.lua"
  2453. local file = fs.open(file7path,"w")
  2454. file.write(file7)
  2455. file.close()
  2456. local file8 = [==[for k,v in pairs(fs.list("rom/")) do
  2457.   print(tostring(k).." "..tostring(v))
  2458. end]==]
  2459. local file8path = "//test"
  2460. local file = fs.open(file8path,"w")
  2461. file.write(file8)
  2462. file.close()
  2463. local file9 = [==[local UpdateList = {
  2464. kernal = {"rom/user/kernal3.lua","SYS_MOUSE/kernal.lua"},
  2465. shell = {"rom/user/shell.lua","SYS_MOUSE/shell.lua"},
  2466. split = {"rom/user/rmt.lua","SYS_MOUSE/split.lua"},
  2467. browse = {"rom/user/selectFile1.lua","SYS_MOUSE/programs/MouseFB.lua"},
  2468. hardware = {"rom/user/TUImethod.lua","SYS_MOUSE/programs/TUImethod.lua"},
  2469. bench = {"rom/user/BENCH4.lua","SYS_MOUSE/programs/Bench.lua"}
  2470. }
  2471. local function update(source,destination)
  2472.     if fs.exists(source) then
  2473.         fs.delete(destination)
  2474.         fs.copy(source,destination)
  2475.         return true
  2476.     end
  2477. end
  2478. for k,v in pairs(UpdateList) do
  2479.     if update(unpack(v)) then
  2480.         print("Updated : "..k)
  2481.     else
  2482.         print("Failed update "..k)
  2483.     end
  2484. end]==]
  2485. local file9path = "//update"
  2486. local file = fs.open(file9path,"w")
  2487. file.write(file9)
  2488. file.close()
  2489. fs.makeDir("//Users")
  2490. fs.makeDir("//Users/admin")
  2491. local file10 = [==[print("random file")]==]
  2492. local file10path = "//Users/admin/random"
  2493. local file = fs.open(file10path,"w")
  2494. file.write(file10)
  2495. file.close()
  2496. fs.makeDir("//Users/admin/randomF")
  2497. local file11 = [==[]==]
  2498. local file11path = "//Users/admin/randomF/randoma"
  2499. local file = fs.open(file11path,"w")
  2500. file.write(file11)
  2501. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement