Advertisement
BigSHinyToys

example

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