Advertisement
BigSHinyToys

[Computer Craft] example core usage

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