Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local file1 = [==[if fs.exists("update") then
- os.run(getfenv(),"update")
- end
- local split = true
- if split then
- if fs.exists("SYS_MOUSE/split.lua") then
- os.run(getfenv(),"SYS_MOUSE/split.lua","left")
- else
- print("Split unavalible")
- end
- end
- print("system loading")
- for k,v in pairs(rs.getSides()) do
- print("Device "..v.." : "..(peripheral.getType(v) or ""))
- end
- print("checking system folder")
- if fs.exists("SYS_MOUSE") then
- print("SYS_MOUSE located")
- if fs.exists("SYS_MOUSE/apis") then
- print("loading apis")
- local list = fs.list("SYS_MOUSE/apis")
- for k,v in pairs(list) do
- os.loadAPI("SYS_MOUSE/apis/"..v)
- print("loaded : "..v)
- end
- end
- if fs.exists("SYS_MOUSE/kernal.lua") then
- print("running kernal")
- return os.run(getfenv(),"SYS_MOUSE/kernal.lua")
- end
- else
- error("system core not found\nplease contact system vendor\nreverting to craft os")
- end
- ]==]
- local file1path = "//startup"
- local file = fs.open(file1path,"w")
- file.write(file1)
- file.close()
- fs.makeDir("//SYS_MOUSE")
- local file2 = [==[--[[
- simple kernal
- with FS permitions / enviromant control
- by BigSHinyToys
- ]]--
- function deepcopy(orig)
- local copy
- if type(orig) == 'table' then
- copy = {}
- for orig_key, orig_value in next, orig, nil do
- if orig_key ~= "_G" then
- copy[deepcopy(orig_key)] = deepcopy(orig_value)
- end
- end
- setmetatable(copy, deepcopy(getmetatable(orig)))
- else -- number, string, boolean, etc
- copy = orig
- end
- return copy
- end
- local oldG = deepcopy(_G)
- local logFile = "sysErrorLog"
- local tThreads = {}
- local focused = 1
- local ver = 0.1
- local function customFileSystem(root)
- local newFS = {}
- local backUpFS = fs
- for k,v in pairs(fs) do
- newFS[k] = function(path,...)
- return backUpFS[k](root..path,...)
- end
- end
- return newFS
- end
- local function customFileSystemIO(root)
- local newFS = {}
- local backUpFS = io
- for k,v in pairs(io) do
- newFS[k] = function(path,...)
- return backUpFS[k](root..path,...)
- end
- end
- return newFS
- end
- local function customRun(root)
- local old = os.run
- return function(env,path,...)
- old(env,root..path,...)
- end
- end
- local function sysLog(sDATA)
- file = fs.open(logFile,"a")
- if file then
- file.write(sDATA.."\n")
- file:close()
- return true
- else
- return false
- end
- end
- local function newThread(...)
- sysLog("Thread Request :")
- local input = {...}
- local tEnv = deepcopy(oldG)
- if input[1] == false then
- tEnv.fs = customFileSystem("Users/admin")
- tEnv.shell = {}
- tEnv.shell.resolve = function(path) return path end
- tEnv.io = customFileSystemIO("Users/admin")
- tEnv.os.run = customRun("Users/admin")
- end
- tEnv.os.newThread = newThread
- table.remove(input,1)
- if input[1] and fs.exists(input[1]) then
- sysLog("New Thread : "..tostring(input[1]))
- local program = input[1]
- table.remove(input,1)
- table.insert(
- tThreads,{
- parth = tostring(program),
- env = deepcopy(tEnv),
- main = coroutine.create(function(...) return os.run(tThreads[#tThreads].env,program,...) end)
- }
- )
- sysLog("Thread Made : ")
- sysLog("Input : "..#input)
- local data = {}
- for i = 1,#input do
- table.insert(data,tostring(input[i]))
- end
- sysLog(table.concat(data,"\n"))
- local test = {coroutine.resume(tThreads[#tThreads].main,unpack(input))}
- sysLog("First Output : ")
- data = {}
- for i = 1,#test do
- table.insert(data,tostring(test[i]))
- end
- sysLog(table.concat(data," "))
- sysLog("-- end Thread request --")
- end
- end
- sysLog("---- New log ----")
- newThread(true,"SYS_MOUSE/shell.lua")
- while true do
- local event = {coroutine.yield()} -- non terminataible
- local pos = 1
- while pos <= #tThreads do
- local test , req = coroutine.resume(tThreads[pos].main,unpack(event))
- if coroutine.status(tThreads[pos].main) ~= "dead" and test then
- pos = pos + 1
- else
- sysLog("Thread Crash "..#tThreads.." : "..coroutine.status(tThreads[pos].main).." "..tostring(tThreads[pos].parth).." "..tostring(req))
- table.remove(tThreads,pos)
- if #tThreads == 0 then
- local evnt,rand
- while rand ~= 28 do
- evnt,rand = os.pullEvent("key")
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- print("System Crash loading old Shell")
- return
- end
- end
- end
- end]==]
- local file2path = "//SYS_MOUSE/kernal.lua"
- local file = fs.open(file2path,"w")
- file.write(file2)
- file.close()
- fs.makeDir("//SYS_MOUSE/programs")
- local file3 = [==[--[[
- Basic Testing and dignostic tool
- by BigShinyToys
- OPEN SOURCE CODE (no rights reserved)
- ]]--
- -- varibles
- local BENCHver = 1.3
- local bRunning = true
- local tSideList = rs.getSides()
- local iTerminalID = os.getComputerID()
- local iPosq = 1
- -- functions
- local function menu(...) -- ver 0.1
- local sel = 1
- local list = {...}
- local offX,offY = term.getCursorPos()
- local curX,curY = term.getCursorPos()
- while true do
- if sel > #list then sel = 1 end
- if sel < 1 then sel = #list end
- for i = 1,#list do
- term.setCursorPos(offX,offY+i-1)
- if sel == i then
- print("["..list[i].."]")
- else
- print(" "..list[i].." ")
- end
- end
- while true do
- local e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up key
- sel = sel-1
- break
- end
- if e1 == 208 then -- down key
- sel = sel+1
- break
- end
- if e1 == 28 then
- term.setCursorPos(curX,curY)
- return list[sel],sel
- end
- end
- end
- end
- end
- local function openRednet()
- local listOfSides = rs.getSides()
- for i = 1,6 do
- if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
- rednet.open(listOfSides[i])
- return listOfSides[i]
- end
- end
- end
- -- apps
- local function RedstoneControl()
- local e,e1,e2,e3,e4,e5
- local function expand(iInput)
- local tOutput = {}
- local check = 32768
- for i = 1,16 do
- if iInput >= check then
- tOutput[i] = 1
- iInput = iInput - check
- else
- tOutput[i] = 0
- end
- check = check/2
- end
- return tOutput
- end
- local function compact(tInput)
- local iOutput = 0
- local check = 1
- for i = 16,1,-1 do
- if tInput[i] == 1 then
- iOutput = iOutput + check
- end
- check = check*2
- end
- return iOutput
- end
- function test(sInput,offX,offY,curPos)
- term.setCursorPos(offX,offY)
- write(sInput)
- offX = offX + 7
- term.setCursorPos(offX,offY)
- local iStatusB = rs.getBundledInput(sInput)
- if peripheral.isPresent(sInput) then
- write(" ")-- blank's out the space for the name
- term.setCursorPos(offX,offY)
- write(peripheral.getType(sInput))
- else
- local invar = expand(iStatusB)
- local text = ""
- for i = 1,#invar do
- text = text..invar[i]
- end
- write(text)
- end
- local iStatusA = rs.getBundledOutput(sInput)
- local invar = expand(iStatusA)
- term.setCursorPos(offX+17,offY)
- write(" "..tostring(rs.getInput(sInput)).." "..iStatusB.." ")
- term.setCursorPos(offX+17,offY+1)
- write(" "..tostring(rs.getOutput(sInput)).." "..iStatusA.." ")
- term.setCursorPos(offX,offY+1)
- text = ""
- for i = 1,#invar do
- text = text..invar[i]
- end
- write(text)
- term.setCursorPos(offX,offY+2)
- write(" ")
- if curPos then
- if curPos > 16 then
- spacer = 4
- else
- spacer = 0
- end
- term.setCursorPos(offX+curPos-1+spacer,offY+2)
- write("^")
- end
- end
- local tSideList = rs.getSides()
- local curX,curY = 1,1
- local spacer = 0
- term.clear()
- term.setCursorPos(1,1)
- while true do
- if e == "key" then
- if e1 == 14 then -- Backspace
- return
- end
- if e1 == 200 then -- up key
- curY = curY -1
- end
- if e1 == 208 then -- down key
- curY = curY +1
- end
- if e1 == 203 then -- left key
- curX = curX -1
- end
- if e1 == 205 then -- right key
- curX = curX +1
- end
- if e1 == 28 then
- if curX == 17 then
- if rs.getOutput(tSideList[curY]) then
- rs.setOutput(tSideList[curY],false)
- else
- rs.setOutput(tSideList[curY],true)
- end
- else
- local total = expand(rs.getBundledOutput(tSideList[curY]))
- if total[curX] == 1 then
- total[curX] = 0
- else
- total[curX] = 1
- end
- rs.setBundledOutput(tSideList[curY],compact(total))
- end
- end
- end
- if curY > 6 then curY = 1 end
- if curY < 1 then curY = 6 end
- if curX > 17 then curX = 1 end
- if curX < 1 then curX = 17 end
- for o = 1,6 do
- if o == curY then
- test(tSideList[o],1,o*3-2,curX)
- else
- test(tSideList[o],1,o*3-2)
- end
- end
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- end
- end
- local function Hardware()
- term.clear()
- term.setCursorPos(1,1)
- print("Under Construction\nPress any key to return to menu.")
- os.pullEvent("key")
- return
- end
- local function wifi()
- local bWiFiRun = true
- local message
- term.clear()
- term.setCursorPos(1,1)
- function readADV() -- slightly modified read function credit to dan200 for original
- term.setCursorBlink( true )
- local sLine = ""
- local nPos = 0
- local w, h = term.getSize()
- local sx, sy = term.getCursorPos()
- local function redraw()
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx, sy )
- term.write( string.rep(" ", w - sx + 1) )
- term.setCursorPos( sx, sy )
- term.write( string.sub( sLine, nScroll + 1 ) )
- term.setCursorPos( sx + nPos - nScroll, sy )
- end
- while true do
- local sEvent, param = os.pullEvent()
- if sEvent == "char" then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- redraw()
- elseif sEvent == "key" then
- if param == 28 then -- Enter
- break
- elseif param == 203 then -- Left
- if nPos > 0 then
- nPos = nPos - 1
- redraw()
- end
- elseif param == 205 then -- Right
- if nPos < string.len(sLine) then
- nPos = nPos + 1
- redraw()
- end
- elseif param == 14 then
- -- Backspace
- if nPos > 0 then
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- end
- else
- redraw()
- end
- end
- term.setCursorBlink( false )
- term.setCursorPos( w + 1, sy )
- return sLine
- end
- local function writer()
- while true do
- coroutine.yield()
- writer2()
- end
- end
- function writer2()
- term.setCursorPos(1,1)
- term.clearLine()
- if stat == "to" then
- write("To :")
- elseif stat == "mes" then
- write("Mes :")
- elseif stat == "fail" then
- write("No target specified press enter to continue.")
- end
- end
- local function send()
- while true do
- local sizX,sizY = term.getSize()
- term.setCursorPos(6,1)
- stat = "to"
- writer2()
- local id = readADV()
- if id == "exit" then
- bWiFiRun = false
- rednet.close(modemOn)
- return
- elseif id == "all" then
- id = nil
- term.setCursorPos(6,1)
- stat = "mes"
- writer2()
- message = readADV()
- rednet.send(id,message)
- elseif tonumber(id) then
- id = tonumber(id)
- term.setCursorPos(6,1)
- stat = "mes"
- writer2()
- message = readADV()
- rednet.send(id,message)
- else
- stat = "fail"
- writer2()
- os.pullEvent("key")
- end
- end
- end
- local function recive()
- local lastX,lastY = 1,2
- while true do
- term.setCursorBlink( true )
- local event = {coroutine.yield()}
- term.setCursorBlink( false )
- if event[1] == "rednet_message" then
- local sizX,sizY = term.getSize()
- term.setCursorPos(1,lastY)
- print("Frm: "..event[2].." Dist: "..event[4].."M Mes: "..event[3])
- lastX,lastY = term.getCursorPos()
- end
- end
- end
- -- moved openRednet from here
- modemOn = openRednet()
- if not modemOn then
- print("No WIFI Modem\nPress any key to return to menu.")
- os.pullEvent("key")
- return
- else
- print("Opened wifi on "..modemOn.." side")
- end
- term.clear()
- term.setCursorPos(1,1)
- local stat = nil
- local reciveHandel = coroutine.create(recive)
- local writerHandel = coroutine.create(writer)
- local sendHandel = coroutine.create(send)
- coroutine.resume(reciveHandel,e,e1,e2,e3,e4,e5)
- coroutine.resume(writerHandel)
- coroutine.resume(sendHandel,e,e1,e2,e3,e4,e5)
- while bWiFiRun do -- start a loop
- local e,e1,e2,e3,e4,e5 = os.pullEvent()
- coroutine.resume(reciveHandel,e,e1,e2,e3,e4,e5)
- coroutine.resume(writerHandel)
- coroutine.resume(sendHandel,e,e1,e2,e3,e4,e5)
- end
- end
- local function EventMonitor()
- term.clear()
- term.setCursorPos(1,1)
- print("press BACKSPACE key 14 to exit")
- print("Wating For Event...")
- local tEvents
- while true do
- tEvents = {os.pullEvent()}
- if tEvents[1] == "key" and tEvents[2] == 14 then
- return
- end
- for i = 1,#tEvents do
- write(tostring(tEvents[i]).." ")
- end
- write("\n")
- end
- end
- local function TurtleDriver()
- term.clear()
- term.setCursorPos(1,1)
- if not turtle then
- print("This is Not a Turtle \nPress any key to return")
- os.pullEvent("key")
- return
- end
- local compas = {"n","e","s","w"}
- local turX,turY,turZ = 0,0,0
- local gpsX,gpsY,gpsZ = nil , nil , nil
- local face = 1
- local slotSelX = 1
- local slotSelY = 1
- function move(ins,rep) -- low levle functions
- if not ins and not rep then
- return false,"error no move specified"
- elseif not rep then
- rep = 1
- end
- for i=1,rep do
- if ins == "U" then -- up move
- if turtle.up() then
- turZ = turZ+1
- else
- return false
- end
- end
- if ins == "D" then -- down move
- if turtle.down() then
- turZ = turZ-1
- else
- return false
- end
- end
- if ins == "L" then -- left turn
- if turtle.turnLeft() then
- face = face - 1
- if face < 1 then
- face = 4
- end
- else
- return false
- end
- end
- if ins == "R" then -- right turn
- if turtle.turnRight() then
- face = face + 1
- if face > 4 then
- face = 1
- end
- else
- return false
- end
- end
- if ins == "F" then -- forward move
- if turtle.forward() then
- if face == 1 then
- turY = turY+1
- end
- if face == 2 then
- turX = turX+1
- end
- if face == 3 then
- turY = turY-1
- end
- if face == 4 then
- turX = turX-1
- end
- else
- return false
- end
- end
- if ins == "B" then -- back move
- if turtle.back() then
- if face == 1 then
- turY = turY-1
- end
- if face == 2 then
- turX = turX-1
- end
- if face == 3 then
- turY = turY+1
- end
- if face == 4 then
- turX = turX+1
- end
- else
- return false
- end
- end
- end
- return true
- end
- local function reDraw()
- term.clear()
- term.setCursorPos(1,1)
- print("Compus : "..compas[face].." Loc : X "..turX.." Y "..turY.." Z "..turZ)
- if gpsX then
- print("last GPS ping : X "..gpsX.." Y "..gpsY.." Z "..gpsZ)
- else
- print("GPS position unknown")
- end
- term.setCursorPos(1,3)
- print("Remaning Fuel : "..turtle.getFuelLevel())
- term.setCursorPos(1,5)
- print([[Use "up down left right" keys to select slot then press "r" to refuel from slot.
- Press "g" locate GPS position.
- Press "b" to set Loc as GPS.
- Press "h" to ajust Heading]])
- end
- reDraw()
- while true do
- local e,e1,e2,e3,e4,e5 = os.pullEvent()
- -- print(tostring(e).."-"..tostring(e1))
- if e == "key" then
- if e1 == 17 then
- move("F")
- elseif e1 == 31 then
- move("B")
- elseif e1 == 30 then
- move("L")
- elseif e1 == 32 then
- move("R")
- elseif e1 == 16 then
- move("U")
- elseif e1 == 18 then
- move("D")
- elseif e1 == 14 then -- backspace
- return
- elseif e1 == 19 then -- r
- turtle.refuel(1)
- elseif e1 == 34 then -- g
- local rednetSide = openRednet()
- if rednetSide then
- gpsX,gpsY,gpsZ = gps.locate( 2, false)
- rednet.close(rednetSide)
- else
- print("no WIFI modem connected")
- end
- elseif e1 == 35 then -- h
- face = face +1
- if face > 4 then
- face = 1
- end
- elseif e1 == 200 then -- up turtle.select(e1-1) local slotSelX = 1 local slotSelY = 1
- slotSelY = slotSelY -1
- if slotSelY < 1 then
- slotSelY = 4
- end
- elseif e1 == 208 then -- down
- slotSelY = slotSelY +1
- if slotSelY > 4 then
- slotSelY = 1
- end
- elseif e1 == 203 then -- left
- slotSelX = slotSelX -1
- if slotSelX < 1 then
- slotSelX = 4
- end
- elseif e1 == 205 then -- right
- slotSelX = slotSelX +1
- if slotSelX > 4 then
- slotSelX = 1
- end
- elseif e1 == 48 then -- b
- if gpsX then
- turX,turY,turZ = gpsX,gpsY,gpsZ
- end
- end
- turtle.select(slotSelX+(slotSelY*4)-4)
- end
- reDraw()
- end
- end
- local function help() -- 203 left 205 right
- local tHelp = {
- [[This program is designed for use while testing other programs or redstone systems.
- It allows you the user to change hardware settings quickly and read input from Redstone, Bundled Cable and WiFi.
- Event Monitor will show what events happen. This is usefull for finding the number of a pressed key for example BackSpace is key 14.
- OPEN SOURCE CODE (no rights reserved) 2012
- By Big Shiny Toys ver ]]..BENCHver.."\n\nPress Backspace to return to menu.",
- "section 2",
- "section 3",
- }
- local iPage = 1
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print(tHelp[iPage])
- term.setCursorPos(10,18)
- write("- Page "..iPage.." of "..#tHelp.." -")
- local e,e1,e2 = os.pullEvent("key")
- if e == "key" then
- if e1 == 203 then -- left
- iPage = iPage - 1
- elseif e1 == 205 then -- right
- iPage = iPage + 1
- elseif e1 == 14 then -- Backspace
- return
- end
- end
- if iPage < 1 then iPage = 1 end
- if iPage > #tHelp then iPage = #tHelp end
- end
- end
- -- Top Loop
- while bRunning do
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to BENCH ver "..BENCHver.." terminal "..iTerminalID.."\nBy Big Shiny Toys")
- term.setCursorPos(2,4)
- term.setCursorBlink(false)
- local selection = menu("Redstone","Hardware","WiFi","Event Monitor","Turtle Driver","Infomation/Help","Exit")
- if selection == "Redstone" then
- RedstoneControl()
- elseif selection == "Hardware" then
- Hardware()
- elseif selection == "WiFi" then
- wifi()
- elseif selection == "Event Monitor" then
- EventMonitor()
- elseif selection == "Turtle Driver" then
- TurtleDriver()
- elseif selection == "Infomation/Help" then
- help()
- elseif selection == "Exit" then
- bRunning = false
- end
- end
- term.clear()
- term.setCursorPos(1,1)]==]
- local file3path = "//SYS_MOUSE/programs/Bench.lua"
- local file = fs.open(file3path,"w")
- file.write(file3)
- file.close()
- local file4 = [==[--[[
- Mouse File Browser
- by:
- Stiepen irc(Kilobyte)
- Cruor
- BigSHinyToys
- note: send link to nightin9ale on CC forums
- --]]
- local tArgs = {...}
- local ver = "1.0"
- local sTitle = "File Browser"
- local bugTest, norun, dir, showAll
- local _tArgs = {}
- local function help()
- print("Usage: browser [-d] [-h] [-a] [--debug] [--help] [--dir <dir>] [--all]")
- print("--debug or -d: enable debug mode")
- print("--help or -h: display this screen")
- print("--dir: define initial directory")
- print("--all or -a: show hidden files")
- print("-u: update")
- end
- for a = 1, #tArgs do
- if tArgs[a]:sub(1,2) == "--" then
- local cmd = tArgs[a]:sub(3):lower()
- if cmd == "debug" then
- bugTest = true
- elseif cmd == "help" then
- help()
- norun = true
- elseif cmd == "dir" then
- dir = tArgs[a+1]
- a = a + 1
- elseif cmd == "all" then
- showAll = true
- end
- elseif tArgs[a]:sub(1,1) == "-" then
- for b = 2, #tArgs[a] do
- cmd = tArgs[a]:sub(b, b)
- if cmd == "d" then
- bugTest = true
- elseif cmd == "h" then
- help()
- norun = true
- elseif cmd == "p" then
- dir = tArgs[a+1]
- a = a + 1
- elseif cmd == "a" then
- showAll = true
- elseif cmd == "u" then
- print("Checking for Updates")
- local isHTTP = false
- local response
- if http then
- isHTTP = true
- print("http on")
- response = http.get("http://pastebin.com/raw.php?i=rLbnyM1U")
- end
- local flag = false
- local isNewFlag = false
- local newVerID
- if response and isHTTP then
- print("recived")
- local sInfo = response.readLine()
- print(sInfo)
- while sInfo do
- print(sInfo)
- if flag then
- if sInfo == ver then
- print("Mouse File Browser is up to date")
- break
- else
- newVerID = sInfo
- flag = false
- isNewFlag = true
- end
- elseif sInfo == sTitle then
- flag = true
- elseif isNewFlag then
- isNewFlag = sInfo
- response.close()
- break
- end
- sInfo = response.readLine()
- end
- if isNewFlag then
- print("New vershion avalible "..newVerID)
- print('downloading to \Browser')
- if fs.exists("Browser") then
- write("Browser exists OverWrite Browser Y/N : ")
- local input = string.lower(read())
- while input ~= "y" and input ~= "n" do
- print("y or n required")
- input = string.lower(read())
- end
- if input == "y" then
- print("Over Writeing Browser")
- print("Downloading new File")
- local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag)
- if response then
- print("file downloaded")
- print("installing")
- fs.delete("Browser")
- local handel = fs.open("Browser","w")
- if handel then
- handel.write(response.readAll())
- handel.close()
- print("Update Complete")
- end
- response.close()
- end
- else
- print("Update aborted")
- end
- else
- print("Downloading new File")
- local response = http.get("http://pastebin.com/raw.php?i="..isNewFlag)
- if response then
- print("file downloaded")
- print("installing")
- local handel = fs.open("Browser","w")
- if handel then
- handel.write(response.readAll())
- handel.close()
- print("Update Complete")
- end
- response.close()
- end
- end
- end
- elseif isHTTP then
- print("Error downloading update file Please contact BigSHinyToys on the CC forums")
- print("http://www.computercraft.info/forums2/index.php?/topic/5509-advanced-computer-mouse-file-browser/")
- elseif not isHTTP then
- print("HTTP API is turned off")
- print("Access Computer Craft Configer and change line")
- print([[enableapi_http {
- # Enable the "http" API on Computers
- general=false
- }
- TO THIS :
- enableapi_http {
- # Enable the "http" API on Computers
- general=true
- }]])
- end
- notCMD = false
- norun = true
- end
- end
- else
- table.insert(_tArgs, tArgs[a])
- end
- end
- if (not dir) and shell and shell.dir then
- dir = shell.dir()
- end
- if dir and shell and shell.resolve then
- dir = shell.resolve(dir)
- end
- dir = dir or "/"
- if bugTest then -- this is that the var is for testing
- print("Dir: "..dir)
- os.startTimer(4)
- os.pullEvent()
- end
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorBlink(false)
- term.setCursorPos(1,1)
- end
- --[[
- Code thanks to Cruor
- http://www.computercraft.info/forums2/index.php?/topic/5802-support-for-shell/
- ]]--
- local function fixArgs(...)
- local tReturn={}
- local str=table.concat({...}," ")
- local sMatch
- while str and #str>0 do
- if string.sub(str,1,1)=="\"" then
- sMatch, str=string.match(str, "\"(.-)\"%s*(.*)")
- else
- sMatch, str=string.match(str, "(%S+)%s*(.*)")
- end
- table.insert(tReturn,sMatch)
- end
- return tReturn
- end
- --[[ end Cruor function ]]--
- -- modified read made to play nice with coroutines
- local function readMOD( _sReplaceChar, _tHistory,_wdth)
- local sLine = ""
- term.setCursorBlink( true )
- local nHistoryPos = nil
- local nPos = 0
- if _sReplaceChar then
- _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
- end
- local sx, sy = term.getCursorPos()
- local w, h = term.getSize()
- if _wdth and type(_wdth) == "number" then
- w = sx + _wdth - 1
- end
- local function redraw( _sCustomReplaceChar )
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx + _wdth - 1, sy )
- term.write(" ")
- term.setCursorPos( sx, sy )
- local sReplace = _sCustomReplaceChar or _sReplaceChar
- if sReplace then
- term.write( string.rep(sReplace,_wdth) )
- else
- term.write( string.sub( sLine, nScroll + 1 ,nScroll + _wdth) )
- end
- term.setCursorPos( sx + nPos - nScroll, sy )
- end
- while true do
- local sEvent, param = os.pullEvent()
- if sEvent == "char" then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- redraw()
- elseif sEvent == "key" then
- if param == keys.left then
- -- Left
- if nPos > 0 then
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.right then
- -- Right
- if nPos < string.len(sLine) then
- nPos = nPos + 1
- redraw()
- end
- elseif param == keys.up or param == keys.down then
- -- Up or down
- if _tHistory then
- redraw(" ");
- if param == keys.up then
- -- Up
- if nHistoryPos == nil then
- if #_tHistory > 0 then
- nHistoryPos = #_tHistory
- end
- elseif nHistoryPos > 1 then
- nHistoryPos = nHistoryPos - 1
- end
- else
- -- Down
- if nHistoryPos == #_tHistory then
- nHistoryPos = nil
- elseif nHistoryPos ~= nil then
- nHistoryPos = nHistoryPos + 1
- end
- end
- if nHistoryPos then
- sLine = _tHistory[nHistoryPos]
- nPos = string.len( sLine )
- else
- sLine = ""
- nPos = 0
- end
- redraw()
- end
- elseif param == keys.backspace then
- -- Backspace
- if nPos > 0 then
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.home then
- -- Home
- nPos = 0
- redraw()
- elseif param == keys.delete then
- if nPos < string.len(sLine) then
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
- redraw()
- end
- elseif param == keys["end"] then
- -- End
- nPos = string.len(sLine)
- redraw()
- end
- elseif sEvent == "redraw" then
- redraw()
- elseif sEvent == "return" then
- term.setCursorBlink( false )
- return sLine
- end
- end
- term.setCursorBlink( false )
- return sLine
- end
- -- end modified read
- local function printC(posX,posY,textCol,backCol,text)
- term.setCursorPos(posX,posY)
- term.setTextColor(colors[textCol] or textCol)
- term.setBackgroundColor(colors[backCol] or backCol)
- term.write(text)
- end
- local function InputBox(title)
- local boxW,boxH = 26,3
- local termX,termY = term.getSize()
- local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left
- local options = {"ok","cancel"}
- local selected = 1
- local space = 0
- local range = {}
- for i = 1,#options do
- range[i] = {s = space,f = space + string.len(options[i])}
- space = space + string.len(options[i])+3
- end
- local ofC = (boxW/2) - (space/2)
- local function drawBox()
- printC(ofsX,ofsY,colors.black,colors.blue,string.rep(" ",boxW))
- printC(ofsX+1,ofsY,colors.black,colors.blue,(title or "User Input"))
- printC(ofsX,ofsY+1,colors.black,colors.white,string.rep(" ",boxW))
- printC(ofsX,ofsY+2,colors.black,colors.white,string.rep(" ",boxW))
- printC(ofsX,ofsY+3,colors.black,colors.white,string.rep(" ",boxW))
- for i = 1,#options do
- if i == selected then
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
- term.write("["..options[i].."]")
- term.setBackgroundColor(colors.white)
- term.write(" ")
- else
- term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
- term.write(" "..options[i].." ")
- end
- end
- printC(ofsX+2,ofsY+2,colors.black,colors.lightGray,string.rep(" ",boxW-4))
- end
- drawBox()
- term.setCursorPos(ofsX+2,ofsY+2)
- local co = coroutine.create(function() return readMOD(nil,nil,boxW - 4) end)
- while true do
- local event = {os.pullEvent()}
- if event[1] == "key" or event[1] == "char" then
- if event[2] == 28 then
- local test,data = coroutine.resume(co,"return")
- return data
- else
- coroutine.resume(co,unpack(event))
- end
- elseif event[1] == "mouse_click" then
- if event[4] == ofsY + 3 then
- for i = 1,#options do
- if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then
- if options[i] == "ok" then
- local test,data = coroutine.resume(co,"return")
- return data
- elseif options[i] == "cancel" then
- return false
- end
- end
- end
- end
- end
- end
- end
- local function dialogBox(title,message,options, h, w)
- term.setCursorBlink(false)
- local selected = 1
- title = title or ""
- message = message or ""
- options = options or {}
- local boxW,boxH = (w or 26), (h or 3)
- local termX,termY = term.getSize()
- local ofsX,ofsY = math.ceil((termX/2) - (boxW/2)) , math.ceil((termY/2) - (boxH/2)) -- offset from top left
- local space = 0
- local range = {}
- for i = 1,#options do
- range[i] = {s = space,f = space + string.len(options[i])}
- space = space + string.len(options[i])+3
- end
- local ofC = math.ceil((boxW/2)) - math.ceil((space/2))
- local function drawBox()
- printC(ofsX,ofsY,"black","blue"," "..title..string.rep(" ",boxW-#title-5).."_[]")
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.write("X")
- printC(ofsX,ofsY+1,"black","white",string.sub(" "..message..string.rep(" ",boxW),1,boxW))
- term.setCursorPos(ofsX,ofsY+2)
- term.write(string.rep(" ",boxW))
- term.setCursorPos(ofsX,ofsY+3)
- term.write(string.rep(" ",boxW))
- for i = 1,#options do
- if i == selected then
- printC(range[i].s + ofC + ofsX - 1,ofsY + 3,"black","lightGray","["..options[i].."]")
- term.setBackgroundColor(colors.white)
- term.write(" ")
- else
- term.setCursorPos(range[i].s + ofC + ofsX - 1,ofsY + 3)
- term.write(" "..options[i].." ")
- end
- end
- term.setCursorPos(ofsX + ofC + space,ofsY + 3)
- term.write(string.rep(" ",boxW - (ofC + space)))
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- while true do
- drawBox()
- event = {os.pullEvent()}
- if event[1] == "key" then
- if event[2] == 203 then -- left
- selected = selected - 1
- if selected < 1 then
- selected = #options
- end
- elseif event[2] == 205 then -- right
- selected = selected + 1
- if selected > #options then
- selected = 1
- end
- elseif event[2] == 28 then -- enter
- return selected , options[selected]
- end
- elseif event[1] == "mouse_click" then
- if bugTest then term.write("M "..event[2].." X "..event[3].." Y "..event[4].." ") end
- if event[2] == 1 then
- if event[4] == ofsY + 3 then
- for i = 1,#options do
- if event[3] >= range[i].s + ofC + ofsX - 1 and event[3] <= range[i].f + ofC + ofsX then
- return i , options[i]
- end
- end
- end
- end
- end
- end
- end
- local function rClickMenu(title,tList,posX,posY)
- term.setCursorBlink(false)
- local BoxTitle = title
- local choices = tList
- local termX,termY = term.getSize()
- local offX,offY
- local width = #BoxTitle + 2
- local hight = #choices + 1
- for i = 1,#choices do
- if width < #choices[i] + 2 then
- width = #choices[i] + 2
- end
- end
- offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))
- if posX and posY then -- offX,offY = posX,posY
- if posX >= termX - width - 1 then
- offX = termX - width - 1
- else
- offX = posX
- end
- if posY >= termY - hight then
- offY = termY - hight
- else
- offY = posY
- end
- end
- local function reDrawer()
- printC(offX,offY,colors.black,colors.blue," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1))
- for i = 1,#choices do
- printC(offX,offY + i,colors.black,colors.white," "..choices[i]..string.rep(" ",width - #choices[i] - 1))
- end
- end
- while true do
- reDrawer()
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- event[3] = x event[4] = y
- if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then
- return choices[event[4] - offY]
- else
- return
- end
- elseif event[2] == 2 then
- return
- end
- end
- end
- end
- local function osRunSpaces(...)
- clear()
- if os.newThread then
- os.newThread(false,...)
- else
- return os.run(getfenv(),...)
- end
- end
- local function fileSelect(mode) -- save_file open_file browse < not yet implemented
- local title = sTitle.." "..ver
- local bRun = true
- local flag = true
- local clipboard = nil
- local cut = false
- local termX,termY = term.getSize()
- local offsetX,offsetY = 1,1
- local hight,width = math.ceil(termY-2),math.ceil(termX-2)
- local oldHight,oldWidth
- -- offsets
- local boxOffX,boxOffY = offsetX,offsetY + 2
- local boxH,boxW = hight - 2 ,width - 2
- local barX,barY = offsetX + 1,offsetY + 2
- local barH,barW = 1,width - 1
- local tbarX,tbarY = offsetX + 1,offsetY + 1
- local tbarH,tbarW = 1,width - 1
- local exitX,exitY = offsetX + width - 1 ,offsetY + 1
- local pading = string.rep(" ",boxW)
- local path = {dir:match("[^/]+")}
- local list
- local fSlash = "/"
- local listOff = 0
- local function stringPath() -- compacted this a lot
- return fSlash..table.concat(path,fSlash)
- end
- local sPath
- local tItemList = {}
- local function newList()
- listOff = 0
- flag = true
- tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
- sPath = stringPath()
- local folders = {}
- local files = {}
- local disks = {}
- if not fs.exists(sPath) then
- path = {}
- sPath = stringPath()
- dialogBox("ERROR:","Path no longer exists",{"ok"})
- end
- local test,list = pcall(fs.list,sPath) -- stopes fs.list crash
- if list == nil then
- list = {}
- dialogBox("ERROR : ","fs.list crashed",{"ok"})
- end
- if #path == 0 then
- for i,v in pairs(rs.getSides()) do
- if disk.isPresent(v) then
- if disk.hasData(v) then
- table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
- disks[disk.getMountPath(v)] = true
- elseif disk.hasAudio(v) then
- table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
- end
- end
- end
- end
- for i,v in pairs(list) do
- if fs.isDir(sPath..fSlash..v) then
- table.insert(folders,v)
- else
- table.insert(files,v)
- end
- end
- table.sort(folders)
- table.sort(files)
- for i,v in pairs(folders) do
- if disks[v] == nil then
- table.insert(tItemList,{n = v, id = "folder"})
- end
- end
- for i,v in pairs(files) do
- table.insert(tItemList,{n = v, id = "file"})
- end
- end
- newList()
- local tIcons = {
- back = {tCol = "lightGray",bCol = "blue",txt = " < "},
- disk = {tCol = "lime",bCol = "green",txt = "[*]"},
- audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
- folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
- file = {tCol = "lime",bCol = "cyan",txt = " "}}
- while bRun do
- if flag then
- flag = false
- -- clear
- if oldHight ~= hight and oldWidth ~= width then
- term.setBackgroundColor(colors.black)
- term.clear()
- oldHight,oldWidth = hight,width
- end
- -- draw top title bar
- term.setCursorPos(tbarX,tbarY)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.blue)
- local b = tbarW - #title -2
- if b < 0 then
- b = 0
- end
- term.write(string.sub(" "..title,1,tbarW)..string.rep(" ",b))
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.write("X")
- -- draw location bar
- term.setCursorPos(barX,barY)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- local a = barW - #sPath - 1
- if a < 0 then
- a = 0
- end
- local tmppath = sPath
- if shell and shell.getDisplayName then
- tmppath = shell.getDisplayName(sPath)
- --dialogBox("yay")
- else
- --dialogBox("moop")
- end
- tmppath = tmppath or sPath
- local a = barW - #tmppath - 1
- if a < 0 then
- a = 0
- end
- term.write(string.sub(" "..tmppath,1,barW)..string.rep(" ",a))
- -- draw scroll bar
- if #tItemList > boxH then
- term.setBackgroundColor(colors.lightGray)
- for i = 1,boxH do
- term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
- local scroll = math.floor( boxH* (listOff/(#tItemList-boxH+2)) )+1
- if i == scroll then
- term.setBackgroundColor(colors.gray)
- term.write(" ")
- term.setBackgroundColor(colors.lightGray)
- else
- term.write(" ")
- end
- end
- else
- term.setBackgroundColor(colors.gray)
- for i = 1,boxH do
- term.setCursorPos(boxOffX+boxW+1,i + boxOffY)
- term.write(" ")
- end
- end
- -- draw main section
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.cyan)
- for i = 1,boxH do -- listOff
- --term.setCursorPos(1+boxOffX,i+boxOffY)
- local sel = i+listOff
- if tItemList[sel] then
- printC(1+boxOffX,i+boxOffY,colors[tIcons[tItemList[sel].id].tCol],colors[tIcons[tItemList[sel].id].bCol],tIcons[tItemList[sel].id].txt)
- printC(4+boxOffX,i+boxOffY,"black","cyan",string.sub(" "..tItemList[sel].n..pading,1,boxW-3))
- else
- printC(1+boxOffX,i+boxOffY,"black","cyan",pading)
- end
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if bugTest then
- term.setCursorPos(1,1)
- term.write(listOff.." "..boxOffY.." "..boxH)
- end
- end
- -- react to events
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- left mouse
- local temp = nil
- if event[4] > boxOffY and event[4] <= boxH + boxOffY then
- temp = tItemList[event[4]+listOff-boxOffY]
- end
- if temp and event[3] > boxOffX and event[3] <= #temp.n + 4 + boxOffX and event[3] < boxOffX + boxW then
- if temp.id == "back" then
- table.remove(path,#path)
- newList()
- elseif temp.id == "folder" or temp.id == "disk" then
- table.insert(path,temp.n)
- newList()
- elseif temp.id == "file" then
- if dialogBox("Run file ?",temp.n,{"yes","no"}) == 1 then
- local test,info = osRunSpaces(stringPath()..fSlash..temp.n)
- term.setCursorBlink(false)
- if not test then
- dialogBox("ERROR",tostring(info),{"ok"})
- end
- end
- flag = true
- end
- elseif event[3] == boxOffX+boxW+1 and event[4] > boxOffY and event[4] <= boxOffY+boxH then
- if #tItemList > boxH then
- if event[4] == boxOffY + 1 then
- listOff = 0
- elseif event[4] == boxOffY+boxH then
- listOff = #tItemList + 1 - boxH
- else
- listOff = math.ceil((event[4] - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH)))
- end
- flag = true
- end
- elseif event[3] == exitX and event[4] == exitY then
- if dialogBox("Confirm","Exit application",{"yes","no"}) == 1 then
- bRun = false
- end
- flag = true
- end
- elseif event[2] == 2 then -- right mouse
- local temp = nil
- local sChoice = nil
- if event[4] > boxOffY and event[4] <= boxH + boxOffY then
- temp = tItemList[event[4]+listOff-boxOffY]
- end
- -- moved
- local paste
- if clipboard then
- paste = "Paste"
- end
- if temp and event[3] > boxOffX and event[3] <= #temp.n + 4 + boxOffX and event[3] < boxOffX + boxW then
- if temp.id == "disk" then
- sChoice = rClickMenu("Options",{"Open","Copy","Eject","ID label","Set label","Clear label"},event[3]+1,event[4]+1)
- elseif temp.id == "folder" then
- sChoice = rClickMenu("Options",{"Open","Copy","Delete"},event[3]+1,event[4]+1)
- elseif temp.id == "file" then
- sChoice = rClickMenu("Options",{"Run","Open With","Rename","Delete", "Cut", "Copy", paste},event[3]+1,event[4]+1)
- elseif temp.id == "audio" then
- sChoice = rClickMenu("Options",{"Play","Eject"},event[3]+1,event[4]+1)
- end
- else
- if event[3] > boxOffX and event[3] <= 5 + boxOffX and event[3] < boxOffX + boxW then
- if event[4] > offsetY and event[4] < hight + offsetY then
- sChoice = rClickMenu("Options",{"New File","New Folder", paste},event[3]+1,event[4]+1)
- end
- else
- table.remove(path,#path)
- newList()
- end
- end
- if sChoice == "Open With" then
- sChoice = rClickMenu("Options",{"Edit","Paint"},event[3]+12,event[4]+1)
- elseif sChoice == "Run" then
- local runWin
- if windowDimensions then
- runWin = "Run win"
- end
- sChoice = rClickMenu("Options",{"Run","Run CMD","Debug",runWin},event[3]+12,event[4]+1)
- end
- if sChoice == "Run win" and windowDimensions then -- choice execution
- osRunSpaces("start",stringPath()..fSlash..temp.n) -- might be a probblem -- shell
- flag = true
- elseif sChoice == "Play" then
- disk.playAudio(temp.s)
- elseif sChoice == "ID label" then
- dialogBox("ID label",disk.getDiskID(temp.s).." "..tostring(disk.getLabel(temp.s)),{"ok"})
- elseif sChoice == "Set label" then
- local name = InputBox("Label?")
- if name then
- disk.setLabel(temp.s,name)
- end
- elseif sChoice == "Clear label" then -- dialogBox(
- if dialogBox("Confirm","Cleal Label from "..temp.s,{"yes","no"}) == 1 then
- disk.setLabel(temp.s)
- end
- --[[
- elseif sChoice == "CHIP 8" then -- this was a temp hackin will be going
- local function openDevice(sType)
- for i,v in pairs(rs.getSides()) do
- if peripheral.isPresent(v) and peripheral.getType(v) == sType then
- return peripheral.wrap(v),v
- end
- end
- end
- local func,side = openDevice("monitor")
- osRunSpaces("chip8",stringPath()..fSlash..temp,side)
- ]]--
- elseif sChoice == "New File" then -- experemntal
- local name = InputBox()
- if name then
- if fs.exists(stringPath()..fSlash..name) then
- dialogBox("ERROR","Name exists",{"ok"})
- else
- local file = fs.open(stringPath()..fSlash..name,"w")
- if file then
- file.write("")
- file.close()
- newList()
- else
- dialogBox("ERROR","File not created",{"ok"})
- end
- end
- end
- elseif sChoice == "New Folder" then -- experemental
- local name = InputBox()
- if name then
- if fs.exists(stringPath()..fSlash..name) then
- dialogBox("ERROR","Name exists",{"ok"})
- else
- if pcall(fs.makeDir,stringPath()..fSlash..name) then
- newList()
- else
- dialogBox("ERROR","Access Denied",{"ok"})
- end
- end
- end
- elseif sChoice == "Open" then
- table.insert(path,temp.n)
- newList()
- elseif sChoice == "Run" then
- local test,info = osRunSpaces(stringPath()..fSlash..temp.n)
- term.setCursorBlink(false)
- if not test then
- dialogBox("ERROR",tostring(info),{"ok"})
- end
- elseif sChoice == "Run CMD" or sChoice == "Debug" then
- local cmd = InputBox("Commands")
- if cmd then
- local test,info = osRunSpaces(stringPath()..fSlash..temp.n,unpack(fixArgs(cmd)))
- term.setCursorBlink(false)
- if not test then
- dialogBox("ERROR",tostring(info),{"ok"})
- else
- if sChoice == "Debug" then
- term.setCursorBlink(false)
- os.pullEvent("key")
- end
- end
- end
- elseif sChoice == "Edit" then
- if temp.id == "file" then
- osRunSpaces("/rom/programs/edit",stringPath()..fSlash..temp.n)
- else
- dialogBox("ERROR","Can't edit a Folder",{"ok"})
- end
- elseif sChoice == "Delete" then
- if dialogBox("Confirm","Delete "..temp.id.." "..temp.n,{"yes","no"}) == 1 then
- if fs.isReadOnly(stringPath()..fSlash..temp.n) then
- dialogBox("ERROR",temp.id.." Is read Only",{"ok"})
- else
- fs.delete(stringPath()..fSlash..temp.n)
- newList()
- end
- end
- elseif sChoice == "Paint" then
- if temp.id == "file" then
- osRunSpaces("/rom/programs/color/paint",stringPath()..fSlash..temp.n)
- else
- dialogBox("ERROR","Can't edit a Folder",{"ok"})
- end
- elseif sChoice == "Eject" then
- if dialogBox("Confirm","Eject disk "..temp.s.." "..fSlash..temp.n,{"yes","no"}) == 1 then
- disk.eject(temp.s)
- newList()
- end
- elseif sChoice == "Copy" then
- clipboard = {stringPath(), temp.n}
- cut = false
- elseif sChoice == "Cut" then
- clipboard = {stringPath(), temp.n}
- cut = true
- elseif sChoice == "Paste" then
- if cut then
- local s, m = pcall(function()
- fs.move(clipboard, stringPath().."/"..temp.n)
- cut = false
- clipboard = nil
- end)
- if not s then
- dialogBox("Error", (m or "Couldn't move"), {"ok"}, 4, 30)
- end
- if bugTest then
- local x, y = term.getCursorPos()
- term.setCursorPos(1, ({term.getSize()})[2])
- write("from "..clipboard[1].."/"..clipboard[2].." to "..stringPath().."/"..clipboard[2])
- end
- else
- local s, m = pcall(function()
- fs.copy(clipboard[1].."/"..clipboard[2], stringPath().."/"..clipboard[2])
- end)
- if not s then
- dialogBox("Error", (m or "Couldn't copy"), {"ok"}, 4, 30)
- end
- if bugTest then
- local x, y = term.getCursorPos()
- term.setCursorPos(1, ({term.getSize()})[2])
- write("from "..clipboard[1].."/"..clipboard[2].." to "..stringPath().."/"..clipboard[2])
- end
- end
- newList()
- elseif sChoice == "Rename" then -- new parts of the above thanks kilo
- local sName = InputBox("New Name")
- if type(sName) == "string" and sName ~= "" then
- local s, m = pcall(function()
- fs.move(stringPath()..fSlash..temp.n,stringPath()..fSlash..sName)
- end)
- if not s then
- dialogBox("Error", (m or "Rename failed"), {"ok"})
- end
- end
- newList()
- end
- flag = true
- end
- elseif event[1] == "mouse_scroll" then -- flag this needs new math
- local old = listOff
- listOff = listOff + event[2]
- if listOff < 0 then
- listOff = 0
- end
- if #tItemList + 1 - boxH > 0 and listOff > #tItemList + 1 - boxH then
- listOff = #tItemList + 1 - boxH
- elseif listOff > 0 and #tItemList + 1 - boxH < 0 then
- listOff = 0
- end
- if listOff ~= old then
- flag = true
- end
- elseif event[1] == "mouse_drag" then -- test
- if event[3] == boxOffX+boxW+1 and event[4] > boxOffY and event[4] <= boxOffY+boxH then
- if #tItemList > boxH then
- if event[4] == boxOffY + 1 then
- listOff = 0
- elseif event[4] == boxOffY+boxH then
- listOff = #tItemList + 1 - boxH
- else
- listOff = math.ceil((event[4] - boxOffY - 1 )*(((#tItemList - boxH+2)/boxH)))
- end
- flag = true
- end
- end
- elseif event[1] == "disk" or event[1] == "disk_eject" then
- newList()
- elseif event[1] == "window_resize" then
- termX,termY = term.getSize()
- offsetX,offsetY = 1,1
- hight,width = math.ceil(termY-2),math.ceil(termX-2)
- boxOffX,boxOffY = offsetX,offsetY + 2
- boxH,boxW = hight - 2 ,width - 2
- barX,barY = offsetX + 1,offsetY + 2
- barH,barW = 1,width - 1
- tbarX,tbarY = offsetX + 1,offsetY + 1
- tbarH,tbarW = 1,width - 1
- exitX,exitY = offsetX + width - 1 ,offsetY + 1
- pading = string.rep(" ",boxW)
- flag = true
- elseif event[1] == "redraw" then
- flag = true
- end
- end
- end
- local function main()
- if term.isColor() then
- clear()
- fileSelect()
- clear()
- else
- error("Not an Advanced Computer (gold) ")
- end
- end
- local trash = (norun or main())]==]
- local file4path = "//SYS_MOUSE/programs/MouseFB.lua"
- local file = fs.open(file4path,"w")
- file.write(file4)
- file.close()
- local file5 = [==[--[[
- method decovery
- by BigSHinyToys
- ]]--
- local tab = 1
- local tSide = rs.getSides()
- local width,hight = term.getSize()
- local space = math.floor(width/6)
- local methods = {}
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorBlink(false)
- term.setCursorPos(1,1)
- end
- local function clearL(y)
- term.setCursorPos(1,y)
- term.clearLine()
- end
- local function clearBox(backCol)
- term.setBackgroundColor(colors[backCol])
- for i = 2,hight do
- clearL(i)
- end
- end
- local function setCol(textCol,backCol)
- term.setTextColor(colors[textCol])
- term.setBackgroundColor(colors[backCol])
- end
- local function printC(posX,posY,textCol,backCol,text)
- term.setCursorPos(posX,posY)
- term.setTextColor(colors[textCol])
- term.setBackgroundColor(colors[backCol])
- term.write(text)
- end
- local function drawTabs()
- for i = 1,6 do
- if i == tab then
- printC((space*(i-1))+1,1,"green","lime","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
- else
- printC((space*(i-1))+1,1,"blue","lightBlue","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
- end
- end
- printC(width,1,"white","red","X")
- end
- local function drawData()
- if peripheral.isPresent(tSide[tab]) then
- local pos = 3
- printC(1,2,"green","lime","Peripheral : "..peripheral.getType(tSide[tab]))
- methods = peripheral.getMethods(tSide[tab])
- for i,v in pairs(methods) do
- printC(1,pos,"green","lime",tostring(i).." "..tostring(v))
- pos = pos + 1
- end
- else
- printC(1,2,"green","lime","Peripheral : NIL")
- methods = {}
- end
- end
- clear()
- local lastTab
- local function draw()
- clearBox("lime")
- drawTabs()
- drawData()
- lastTab = tab
- end
- while true do
- if lastTab ~= tab then
- draw()
- end
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- left click
- if event[4] == 1 then -- first line
- for i = 1,6 do
- if event[3] > space*(i-1) and event[3] < (space*(i))+1 then
- tab = i
- end
- end
- if event[3] == width then
- break
- end
- 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
- draw()
- local test = {pcall(peripheral.call,tSide[tab],methods[event[4] - 2])}
- term.setCursorPos(1,hight - 1)
- setCol("red","lightBlue")
- write(tostring(methods[event[4] - 2]).." ")
- for i = 1,#test do
- write(tostring(test[i]).." ")
- end
- end
- end
- elseif event[1] == "peripheral" or event[1] == "peripheral_detach" then
- lastTab = nil
- end
- end
- clear()]==]
- local file5path = "//SYS_MOUSE/programs/TUImethod.lua"
- local file = fs.open(file5path,"w")
- file.write(file5)
- file.close()
- local file6 = [==[--[[
- desktop
- by BigSHinyToys
- ]]--
- local ver = "ALPHA"
- local positions = {}
- local lastClick = false
- local clickTimer
- local lastObject
- local icons = {}
- local startBGColor = "cyan"
- local startTColor = "blue"
- local taskBarColor = "lightBlue"
- local doubleClickTime = 0.5
- local termX,termY = term.getSize()
- local user
- local timeUpdate
- local redNet = false
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorBlink(false)
- term.setCursorPos(1,1)
- end
- local function tag(this)
- print(this)
- os.pullEvent()
- end
- local function colorSet(textColor,backColor)
- term.setTextColor(colors[textColor])
- term.setBackgroundColor(colors[backColor])
- end
- local function openDevice(sType)
- for i,v in pairs(rs.getSides()) do
- if peripheral.isPresent(v) and peripheral.getType(v) == sType then
- return peripheral.wrap(v),v
- end
- end
- end
- local function printC(posX,posY,textCol,backCol,text)
- term.setCursorPos(posX,posY)
- colorSet(textCol,backCol)
- term.write(text)
- end
- local function isObject(hereX,hereY) -- lx left X rx right X ty top Y by bottom Y
- for i,v in pairs(positions) do
- if hereX >= v.lx and hereX <= v.rx and hereY >= v.ty and hereY <= v.by then
- return i
- end
- end
- end
- local function runObject(num)
- clear()
- positions[num].func()
- end
- local function newObject(leftX,rightX,topY,bottomY,thisFunct)
- table.insert(positions,{lx = leftX,rx = rightX,ty = topY,by = bottomY,func = thisFunct})
- return #positions
- end
- local function runProg(...)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if os.newThread then
- return os.newThread(false,...)
- else
- return os.run(getfenv(),...)
- end
- end
- local function newIcon(posX,posY,name,file)
- table.insert(icons,{X = posX,Y = posY,label = name,link = file,object = newObject(posX,posX+3,posY,posY+3,function() return runProg(file) end)})
- end
- local function updateIcons()
- for i,v in pairs(icons) do
- v.X = positions[v.object].lx
- v.Y = positions[v.object].ty
- end
- end
- colorSet("white","black")
- term.clear()
- term.setCursorPos(1,1)
- local function reDraw()
- colorSet("white","black")
- term.clear()
- updateIcons()
- printC(1,termY,startTColor,startBGColor,"[START]")
- printC(8,termY,"white",taskBarColor,string.rep(" ",termX-7))
- for i,v in pairs(icons) do
- printC(v.X,v.Y,"black","white"," ")
- printC(v.X,v.Y+1,"black","white"," ")
- printC(v.X,v.Y+2,"black","white"," ")
- printC(v.X,v.Y+3,"black","white",v.label)
- end
- local sTime = textutils.formatTime(os.time())
- if #sTime ~= 8 then
- sTime = " "..sTime
- end
- printC(termX - 7 ,termY,"white","blue",sTime)
- timeUpdate = os.startTimer(1)
- if redNet then
- printC(termX - 12 ,termY,"white","blue"," {(c ")
- else
- printC(termX - 12 ,termY,"red","blue"," {(c ")
- end
- os.queueEvent("redraw")
- end
- local function moveObject(object,posX,posY)
- local sizeX = positions[object].rx - positions[object].lx
- local sizeY = positions[object].by - positions[object].ty
- --print(sizeX.." "..sizeY)
- os.pullEvent()
- positions[object].lx = posX
- positions[object].rx = posX + sizeX
- positions[object].ty = posY
- positions[object].by = posY + sizeY
- reDraw()
- end
- local function rClickMenu(title,tList,posX,posY)
- term.setCursorBlink(false)
- local BoxTitle = title
- local choices = tList
- local termX,termY = term.getSize()
- local offX,offY
- local width = #BoxTitle + 2
- local hight = #choices + 1
- for i = 1,#choices do
- if width < #choices[i] + 2 then
- width = #choices[i] + 2
- end
- end
- offX,offY = math.ceil((termX/2) - (width/2)),math.ceil((termY/2) - (hight/2))
- if posX and posY then -- offX,offY = posX,posY
- if posX >= termX - width - 1 then
- offX = termX - width - 1
- else
- offX = posX
- end
- if posY >= termY - hight then
- offY = termY - hight
- else
- offY = posY
- end
- end
- local function reDrawer()
- printC(offX,offY,"black","blue"," "..BoxTitle..string.rep(" ",width - #BoxTitle - 1))
- for i = 1,#choices do
- printC(offX,offY + i,"black","white"," "..choices[i]..string.rep(" ",width - #choices[i] - 1))
- end
- end
- while true do
- reDrawer()
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- event[3] = x event[4] = y
- if event[4] > offY and event[4] < hight + offY and event[3] >= offX and event[3] < width + offX then
- return choices[event[4] - offY]
- else
- return
- end
- elseif event[2] == 2 then
- return
- end
- end
- end
- end
- local tUser = {
- admin = "",
- ted = "random"
- }
- local img = [[ 555 111
- eeeee eeeeee 555 111
- ee ee ee ee 555 111
- e e e
- e e ee eee 222
- ccc cc cc ccc e eeeeee eee 222
- c c c ce c e ee b eee 222 b
- cc c ceec ee eb b b bb b b
- c c c ccceeee ee eebbb b bb bbb
- ccc cc cc c eeeeee b b bb b b b]]
- local function makeDraw(pic)
- local hex = {"a","b","c","d","e","f"}
- local n = {}
- n["0"] = 1
- for i = 1,9 do
- n[tostring(i)] = 2^(i)
- end
- for i = 10,15 do
- n[hex[i-9]] = 2^(i)
- end
- local tWords = {}
- for match in string.gmatch(pic, "[^\n]+" ) do
- table.insert( tWords, match )
- end
- return function()
- local lines = tWords
- local hex = n
- local termX,termY = term.getCursorPos()
- for i = 1,#lines do
- for b = 1,#lines[i] do
- local this = string.sub(lines[i],b,b)
- if this ~= " " then
- term.setCursorPos(b,i)
- term.setBackgroundColor(hex[this])
- term.write(" ")
- end
- end
- end
- end
- end
- local drawImg = makeDraw(img)
- local function loginScreen()
- local oldPullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- local flag = false
- while true do
- colorSet("red","lightBlue")
- term.clear()
- term.setCursorPos(1,1)
- drawImg()
- colorSet("red","lightBlue")
- if flag then
- term.setCursorPos(1,1)
- write("ERROR : Access Denied")
- end
- term.setCursorPos(1,termY-2)
- write("User : ")
- local sUser = read()
- term.setCursorPos(1,termY-1)
- write("Password : ")
- local pass = read("*")
- if tUser[sUser] and tUser[sUser] == pass then
- print("access Granted")
- user = sUser
- break
- else
- flag = true
- end
- end
- os.pullEvent = oldPullEvent
- end
- newIcon(2,2,"FILE","SYS_MOUSE/programs/MouseFB.lua")
- newIcon(8,2,"BENC","SYS_MOUSE/programs/Bench.lua")
- newIcon(14,2,"HARD","SYS_MOUSE/programs/TUImethod.lua")
- local wrap,sideWIFI = openDevice("modem")
- if sideWIFI then
- rednet.open(sideWIFI)
- redNet = true
- else
- redNet = false
- end
- local function deskTop()
- timeUpdate = os.startTimer(1)
- clear()
- reDraw()
- while true do
- local event = {os.pullEvent()}
- if event[1] == "timer" and event[2] == clickTimer then
- lastClick = false
- elseif event[1] == "mouse_click" then
- if event[2] == 1 and lastClick then -- doubble left click
- if lastObject ~= nil and lastObject == isObject(event[3],event[4]) then
- runObject(lastObject)
- timeUpdate = os.startTimer(1)
- reDraw()
- lastClick = false
- clickTimer = nil
- end
- elseif event[2] == 1 then -- left click
- if event[3] <= 7 and event[4] == termY then
- local sChoice = rClickMenu(user,{"programs","Log off","Shutdown","Reboot"},1,termY)
- if sChoice == "programs" then
- local tList = fs.list("SYS_MOUSE/programs")
- local sProgram = rClickMenu("Programs",tList,11,termY)
- if sProgram then
- clear()
- runProg("SYS_MOUSE/programs/"..sProgram)
- timeUpdate = os.startTimer(1)
- end
- elseif sChoice == "Shutdown" then
- os.shutdown()
- elseif sChoice == "Reboot" then
- os.reboot()
- elseif sChoice == "Log off" then
- break
- end
- reDraw()
- else
- clickTimer = os.startTimer(doubleClickTime)
- lastClick = true
- lastObject = isObject(event[3],event[4])
- end
- elseif event[2] == 2 then -- right click
- lastObject = nil
- elseif event[2] == 3 then -- scroll wheel
- lastObject = nil
- -- runObject(isObject(event[3],event[4]))
- end
- elseif event[1] == "mouse_drag" then
- if event[2] == 1 then
- if lastObject then
- moveObject(lastObject,event[3],event[4])
- lastClick = false
- clickTimer = nil
- end
- end
- elseif event[1] == "timer" then
- if event[2] == timeUpdate then
- local sTime = textutils.formatTime(os.time())
- if #sTime ~= 8 then
- sTime = " "..sTime
- end
- printC(termX - 7 ,termY,"white","blue",sTime)
- timeUpdate = os.startTimer(1)
- end
- elseif event[1] == "peripheral_detach" or event[1] == "peripheral" then
- local wrap,sideWIFI = openDevice("modem")
- if sideWIFI then
- rednet.open(sideWIFI)
- redNet = true
- else
- redNet = false
- end
- reDraw()
- end
- end
- end
- while true do
- while true do
- loginScreen()
- deskTop()
- end
- end]==]
- local file6path = "//SYS_MOUSE/shell.lua"
- local file = fs.open(file6path,"w")
- file.write(file6)
- file.close()
- local file7 = [==[--[[
- splitter
- by BigSHinyToys
- ]]--
- local tArgs = {...}
- local sSide = {}
- for i,v in pairs(rs.getSides()) do
- sSide[v] = true
- end
- local monSide
- local monBig = false
- local termX,termY = term.getSize()
- local customTerm = {}
- -- local moniter
- local oldMon = {}
- local rmtserv = false
- local sendID
- local client
- local function openDevice(sType)
- for i,v in pairs(rs.getSides()) do
- if peripheral.isPresent(v) and peripheral.getType(v) == sType then
- return peripheral.wrap(v),v
- end
- end
- end
- if #tArgs == 1 then
- if sSide[tArgs[1]] then
- monSide = string.lower(tArgs[1])
- if peripheral.isPresent(monSide) and peripheral.getType(monSide) == "monitor" then
- peripheral.call(monSide,"setTextScale",1)
- local monX,monY = peripheral.call(monSide,"getSize")
- if monX >= termX and monY >= termY then
- monBig = true
- else
- peripheral.call(monSide,"setTextScale",0.5)
- monX,monY = peripheral.call(monSide,"getSize")
- if monX >= termX and monY >= termY then
- monBig = true
- else
- print("Monitor to small")
- end
- end
- end
- elseif string.lower(tArgs[1]) == "restore" then
- term.restore()
- end
- elseif #tArgs == 2 then
- if string.lower(tArgs[1]) == "server" then -- sendID
- local device,side = openDevice("modem")
- if side then
- client = tonumber(tArgs[2])
- if client then
- rednet.open(side)
- rmtserv = true
- end
- end
- elseif string.lower(tArgs[1]) == "client" then
- sendID = tonumber(tArgs[2])
- if sendID then
- local device,side = openDevice("modem")
- if side then
- rednet.open(side)
- rmtsend = true
- end
- end
- end
- else
- print("USAGE: <side> or \"restore\" ")
- end
- local function wrap( _sFunction )
- return function( ... )
- peripheral.call(monSide,_sFunction,...)
- return oldMon[_sFunction](...)
- end
- end
- local function wrapSend( _sFunction )
- return function( ... )
- rednet.send(sendID,textutils.serialize({_sFunction,...}))
- return oldMon[_sFunction](...)
- end
- end
- if monBig then
- -- moniter = peripheral.wrap(monSide)
- for k,v in pairs(term.native) do
- oldMon[k] = v
- end
- for k,v in pairs( term.native ) do
- if type( k ) == "string" and type( v ) == "function" then
- customTerm[k] = wrap(k)
- end
- end
- term.redirect(customTerm)
- term.clear()
- term.setCursorPos(1,1)
- print("Running on monitor")
- elseif rmtsend then
- for k,v in pairs(term.native) do
- oldMon[k] = v
- end
- for k,v in pairs( term.native ) do
- if type( k ) == "string" and type( v ) == "function" then
- customTerm[k] = wrapSend(k)
- end
- end
- term.redirect(customTerm)
- term.clear()
- term.setCursorPos(1,1)
- print("Running on monitor")
- elseif rmtserv then
- term.clear()
- term.setCursorPos(1,1)
- print("Running on monitor")
- while true do
- local event,senderID,mes,dist = os.pullEvent()
- if event == "rednet_message" and senderID == client then
- local this = textutils.unserialize(mes)
- local ins = this[1]
- table.remove(this,1)
- term[ins](unpack(this))
- end
- end
- end]==]
- local file7path = "//SYS_MOUSE/split.lua"
- local file = fs.open(file7path,"w")
- file.write(file7)
- file.close()
- local file8 = [==[for k,v in pairs(fs.list("rom/")) do
- print(tostring(k).." "..tostring(v))
- end]==]
- local file8path = "//test"
- local file = fs.open(file8path,"w")
- file.write(file8)
- file.close()
- local file9 = [==[local UpdateList = {
- kernal = {"rom/user/kernal3.lua","SYS_MOUSE/kernal.lua"},
- shell = {"rom/user/shell.lua","SYS_MOUSE/shell.lua"},
- split = {"rom/user/rmt.lua","SYS_MOUSE/split.lua"},
- browse = {"rom/user/selectFile1.lua","SYS_MOUSE/programs/MouseFB.lua"},
- hardware = {"rom/user/TUImethod.lua","SYS_MOUSE/programs/TUImethod.lua"},
- bench = {"rom/user/BENCH4.lua","SYS_MOUSE/programs/Bench.lua"}
- }
- local function update(source,destination)
- if fs.exists(source) then
- fs.delete(destination)
- fs.copy(source,destination)
- return true
- end
- end
- for k,v in pairs(UpdateList) do
- if update(unpack(v)) then
- print("Updated : "..k)
- else
- print("Failed update "..k)
- end
- end]==]
- local file9path = "//update"
- local file = fs.open(file9path,"w")
- file.write(file9)
- file.close()
- fs.makeDir("//Users")
- fs.makeDir("//Users/admin")
- local file10 = [==[print("random file")]==]
- local file10path = "//Users/admin/random"
- local file = fs.open(file10path,"w")
- file.write(file10)
- file.close()
- fs.makeDir("//Users/admin/randomF")
- local file11 = [==[]==]
- local file11path = "//Users/admin/randomF/randoma"
- local file = fs.open(file11path,"w")
- file.write(file11)
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement