Advertisement
BigSHinyToys

seperate FS privilages

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