Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] CC-DOS Interface By: Redxone [[--
- -- IGN: trainerred2000
- -- BIOS: MultMine
- -- Project Leader: Gonow32 :)
- local _osver = "CS-DOS v3.5"
- local w, h = term.getSize()
- _DOS = {
- runQue = "",
- reqFiles = {"batedit"};
- setpos = term.setCursorPos,
- setback = term.setBackgroundColor,
- settext = term.setTextColor,
- curtext = colors.white,
- curback = colors.black,
- clear = function() term.clear() term.setCursorPos(1,1) end;
- inDir = "",
- input_history = {};
- isCmd = false,
- run = true,
- getScreenSize = term.getSize,
- runProg = shell.run,
- echo = true,
- start = function(self,file)
- --]] open file THEN load each string as if it where a command [[--
- f = io.open(shell.resolve(file),"r")
- local errline = 1
- for line in f:lines() do
- dcmd = line
- if(dcmd:sub(1,2) ~= "::" and (dcmd ~= "" or dcmd ~= " ") )then
- local ok = false
- for i = 1, #self.cmds do
- if(dcmd:sub(1,#self.cmds[i].name) == self.cmds[i].name)then
- self.cmds[i].run(self,dcmd:sub(#self.cmds[i].name+2,-1),true)
- errline = errline + 1
- ok=true
- end
- end
- else
- ok = true
- end
- if not ok then
- print(file..":ln"..errline.." unrecognized command : "..dcmd)
- return
- end
- end
- end,
- tcol = function(self,code)
- local bcol = {
- ["0"] = colors.black,
- ["1"] = colors.blue,
- ["2"] = colors.green,
- ["3"] = colors.cyan,
- ["4"] = colors.red,
- ["5"] = colors.purple,
- ["6"] = colors.brown,
- ["7"] = colors.white,
- ["8"] = colors.gray,
- ["9"] = colors.lightBlue,
- ["A"] = colors.lime,
- ["B"] = colors.lightBlue,
- ["C"] = colors.pink,
- ["D"] = colors.pink,
- ["E"] = colors.yellow,
- ["F"] = colors.white,
- }
- if(bcol[code] == nil)then
- return colors.white
- else
- return bcol[code]
- end
- end,
- getfiles = function(self,dir)
- self.settext(colors.white)
- dir=dir.."/"
- local dirs = {}
- local files = {}
- local tBytes = 0
- print("Directory of :"..dir..".")
- for k, v in pairs(fs.list(dir)) do
- if(fs.isDir(dir..v))then table.insert(dirs,v)
- else table.insert(files,v) tBytes = tBytes + fs.getSize(dir..v) end
- end
- textutils.tabulate(colors.orange, dirs, colors.white, files)
- print(" "..#files.." File(s) "..tBytes.." Bytes.")
- print(" "..#dirs.." Dirs(s) "..fs.getFreeSpace(dir).." Bytes Free.")
- self.settext(self.curtext)
- end,
- cmds = {
- {name="cd",desc="Change directory",run=function(self,v)
- if(v=="" or v==" ")then print("The syntax of the command is incorrect. \n") return end
- if(fs.exists(shell.resolve(v)))then
- shell.setDir(shell.resolve(v))
- else
- self.settext(colors.red)
- print("Unknown directory: "..shell.resolve(v).."\n")
- self.settext(colors.white)
- end
- end};
- {name="@echo",desc="",run=function(self,v)
- if(self.echo)then isecho = "on" else isecho = "off" end
- if(v == "" or v == " ")then
- print("echo is "..isecho)
- elseif(v == "off")then
- self.echo = false
- elseif(v == "on")then
- self.echo = true
- else
- print(v)
- end
- end};
- {name="copy",desc="Copy files to a destination",run=function(self,v)
- if(v == "" or v == " ")then
- print("The syntax of the command is incorrect. \n")
- return
- end
- local args = {}
- for i in string.gmatch(v, "%S+") do
- if(#args < 2)then table.insert(args,i) end
- end
- if(#args < 2)then print("The syntax of the command is incorrect. \n") return end
- if(fs.exists(shell.resolve(args[1])))then
- self.runProg('copy',v)
- else
- print("The system could not find the file specified. \n")
- return
- end
- end};
- {name="move",desc="Move files to a destination",run=function(self,v)
- if(v == "" or v == " ")then
- print("The syntax of the command is incorrect. \n")
- return
- end
- local args = {}
- for i in string.gmatch(v, "%S+") do
- if(#args < 2)then table.insert(args,i) end
- end
- if(#args < 2)then print("The syntax of the command is incorrect. \n") return end
- if(fs.exists(shell.resolve(args[1])))then
- self.runProg('move',v)
- else
- print("The system could not find the file specified. \n")
- return
- end
- end};
- {name="rename",desc="Rename files",run=function(self,v)
- if(v == "" or v == " ")then
- print("The syntax of the command is incorrect. \n")
- return
- end
- local args = {}
- for i in string.gmatch(v, "%S+") do
- if(#args < 2)then table.insert(args,i) end
- end
- if(#args < 2)then print("The syntax of the command is incorrect. \n") return end
- if(fs.exists(shell.resolve(args[1])))then
- self.runProg('move',v)
- else
- print("The system could not find the file specified. \n")
- return
- end
- end};
- {name= "mkdir",desc="Make a directory",run=function(self,v)
- if(not fs.exists(shell.resolve(v)) )then
- fs.makeDir(shell.resolve(v))
- else
- print("Directory or file exists. \n")
- end
- end};
- {name= "del",desc="Delete a file or directory",run=function(self,v)
- if( fs.exists(shell.resolve(v)) )then
- fs.delete(shell.resolve(v))
- else
- print("Directory or file doesnt exists. \n")
- end
- end};
- {name="color",desc="Sets console color",run=function(self,v)
- if(#v < 2)then print("The syntax of the command is incorrect. \n") return end
- self.setback(self.tcol(self,v:sub(2,2)))
- self.settext(self.tcol(self,v:sub(1,1)))
- self.curtext = self.tcol(self,v:sub(1,1))
- self.curback = self.tcol(self,v:sub(2,2))
- end};
- {name= "echo",desc="Displays messages",run=function(self,v,isf)
- if(v == "on")then if(isf)then write(">echo on \n") end
- self.echo = true elseif(v == "off")then if(isf)then write(">echo off \n") end
- self.echo = false
- else
- print(v)
- end
- end};
- {name="shutdown",desc="Shutdown the system",run=function(self,v) os.shutdown() end};
- {name="reboot",desc="Reboot the system",run=function(self,v) os.reboot() end};
- {name="time",desc="Displays system time",run=function(self,v) print("The current time is "..textutils.formatTime(os.time(),false).."\n") end};
- --{name="reload",desc="Reload CS-DOS",run=function(self,v) self.run=false self.runProg(shell.getRunningProgram()) return end};
- {name="exit",desc="Exits shell",run = function(self, v) self.run = false return end};
- --{name="error",desc="Test error message",run = function(self, v) error("Exception Caught!") end};
- {name="cls",desc="Clear screen",run = function(self, v) self.clear() end};
- {name="edit",desc="Edit a file",run = function(self, v)
- if(v=="" or v==" ")then
- print("The syntax of the command is incorrect. \n")
- return
- end
- local ed = ""
- for i in v:gmatch("([^.]+)") do
- ed=i
- end
- if(ed == "bat")then
- self.runProg("batedit",v)
- self.settext(colors.white)
- self.setback(colors.black)
- else
- self.runProg("edit",v)
- end
- end};
- {name="start",desc="",run=function(self,v)
- if(fs.exists(shell.resolve(v)))then
- local ed = ""
- for i in v:gmatch("([^.]+)") do
- ed=i
- end
- if(ed == "bat")then
- self:start(v)
- else
- shell.run(shell.resolve(v))
- end
- else
- print("System could not find the file specified: ".._inp..". \n")
- end
- end};
- {name="dir",desc="Lists files and directorys",run = function(self, v)
- if( fs.exists( shell.resolve(v) ) )then
- self.getfiles(self,shell.resolve(v))
- else
- print("System could not find the directory specified. \n")
- end
- end};
- {name="help",desc="Lists all commands",run = function(self, v)
- write("CS-DOS Commands: \n")
- for i = 1, #self.cmds do
- if(self.cmds[i].desc ~= "")then
- write(string.upper(self.cmds[i].name)..string.rep(" ",8 - #self.cmds[i].name))
- local w, h = self.getScreenSize()
- write(" ")
- write(self.cmds[i].desc.."\n")
- end
- end
- end};
- };
- }
- --]] this will make teh program EXTRA LONG [[ --
- -- Get file to edit
- -- Cleanup
- term.clear()
- term.setCursorBlink( false )
- term.setCursorPos( 1, 1 )
- -- end bat editor
- local _logo = {
- " ----- ---- ---- --- ---- ",
- " | | | | | | | ",
- " | | | | | | | ",
- " | ---- | | | | ---- ",
- " | | | | | | | ",
- " | | | | | | | ",
- " ---- ---- ---- --- ---- ",
- }
- _DOS.clear()
- -- functions
- local _printlogo = function()
- _DOS.setback(colors.blue)
- for i = 1, #_logo do
- _DOS.settext(colors.green)
- print(_logo[i])
- _DOS.settext(colors.white)
- end
- print(string.rep(" ",_logo[1]:len()))
- print(_osver,string.rep(" ", (_logo[1]:len() - #_osver )))
- _DOS.setback(colors.black)
- end
- -- Manage
- _system = function()
- if(_DOS.echo)then
- write(shell.dir().."> ")
- end
- _inp = read(nil,_DOS.input_history)
- table.insert(_DOS.input_history,_inp)
- _DOS.isCmd = false
- _inp = string.lower(_inp)
- -- Catch Potential Error --
- _proInp = _inp
- -- check command
- for i = 1, #_DOS.cmds do
- _proInp = _inp:sub(1,#_DOS.cmds[i].name)
- for i in string.gmatch(_proInp, "%S+") do
- nProInp = i
- end
- if(_proInp == nProInp)then nProInp = "" end
- if(_proInp == _DOS.cmds[i].name and nProInp ~= _proInp)then
- _DOS.cmds[i].run(_DOS,_inp:sub(#_DOS.cmds[i].name+2,-1))
- _DOS.isCmd = true
- end
- end
- if(not _DOS.isCmd)then
- if(fs.exists(shell.resolve(_inp)))then
- local ed = ""
- for i in _inp:gmatch("([^.]+)") do
- ed=i
- end
- if(ed == "bat")then
- _DOS:start(_inp)
- else
- shell.run(_inp)
- end
- else
- print("Bad command or file name: ".._inp..". \n")
- end
- end
- end
- -- Commands
- -- Loop
- _OS = function()
- if(not fs.exists("autoexec.bat"))then
- print("system could not find the file autoexec.bat!")
- print("creating...")
- f = fs.open("autoexec.bat","w")
- f.writeLine("::Autoexec generated by CS-DOS::")
- f.writeLine("echo Welcome To CS-DOS! ")
- f.writeLine("time")
- f.close()
- end
- _DOS:start("autoexec.bat")
- print("Starting ".._osver)
- while _DOS.run do
- if(_DOS.runQue ~= "")then
- _DOS.start(_DOS,_DOS.runQue)
- _DOS.runQue = ""
- end
- for i = 1, #_DOS.reqFiles do if(not fs.exists(_DOS.reqFiles[i]) ) then
- error("Required File Not Found: ".._DOS.reqFiles[i])
- end
- end
- local _gud, _value = pcall(_system)
- if(not _gud)then
- print("ERROR SEVERE: ".._value..". \n")
- end
- end
- end
- _OS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement