Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WDOS - Wii's Disk Operating System
- wdos = {defaultModules = {}, oscolor = colors.lime,version = "WDOS v1.0", shutdown = (function() wdos.printOs("Shutting down...") sleep(2) os.shutdown() end)}
- wdos.defaultModules.shutdown = "wdos.shutdown()"
- wdos.defaultModules.reboot = "wdos.printOs(\"Rebooting...\") sleep(2) os.reboot()"
- wdos.defaultModules.disks = [[
- local p = peripheral.getNames()
- for k,v in pairs(p) do
- if fs.exists(disk.getMountPath(v).."/wdos_disk") then
- local f = fs.open(disk.getMountPath(v).."/wdos_disk","r")
- local f2 = textutils.unserialize(f.readAll())
- f.close()
- if f2 ~= nil then
- if f2[name] ~= nil then
- wdos.writeOs(v..": ",colors.white)
- write(f2[name])
- end
- end
- end
- end
- ]]
- wdos.defaultModules.install = [[
- local p = peripheral.getNames()
- local tab = {}
- for k,v in pairs(p) do
- if fs.exists(disk.getMountPath(v).."/wdos_disk") then
- local f = fs.open(disk.getMountPath(v).."/wdos_disk","r")
- local f2 = textutils.unserialize(f.readAll())
- f.close()
- if f2 ~= nil and fs.exists(disk.getMountPath(v).."/module") then
- if string.lower(f2[name]) == string.lower(({...})[1]) then
- table.insert(tab,v)
- end
- end
- end
- end
- if #tab == 1 then
- local f = fs.open(disk.getMountPath(tab[1]).."/wdos_disk","r")
- local f2 = textutils.unserialize(f.readAll())
- f.close()
- if fs.exists(disk.getMountPath(tab[1]).."/module") then
- if string.lower(f2[name]) ~= nil then
- if fs.exists(f2[name]) then
- fs.delete()
- end
- fs.copy(disk.getMountPath(tab[1]).."/module",".wdos/"..f2[name])
- end
- end
- elseif #tab > 1 then
- local choice = wdos.listSelector("More than one source disk found.")
- local f = fs.open(disk.getMountPath(tab[choice]).."/wdos_disk","r")
- local f2 = textutils.unserialize(f.readAll())
- f.close()
- if f2 ~= nil and fs.exists(disk.getMountPath(tab[1]).."/module") then
- if string.lower(f2[name]) ~= nil then
- if fs.exists(f2[name]) then
- fs.delete()
- end
- fs.copy(disk.getMountPath(tab[choice]).."/module",".wdos/"..f2[name])
- end
- end
- if fs.exists(f2[name]) then
- fs.delete()
- end
- fs.copy(disk.getMountPath(tab[1]).."/module",".wdos/"..f2[name])
- else
- printError("No such module.")
- end
- ]]
- wdos.defaultModules.uninstall = [[
- if ({...})[1] ~= nil then
- if fs.exists(".wdos/"..({...})[1]) and fs.combine(({...})[1],".") ~= ".wdos" then
- fs.delete(".wdos/"..({...})[1])
- end
- end
- ]]
- wdos.defaultModules.run = [[
- shell.run(unpack({...}))
- ]]
- wdos.defaultModules.dir = [[
- shell.run("rom/programs/list "..({...})[1])
- ]]
- function os.pullEvent(filter)
- local e = {os.pullEventRaw(filter)}
- if e[1] == "terminate" then
- wdos.shutdown()
- end
- return unpack(e)
- end
- function wdos.split(pString, pPatte)
- local Tae = {}
- local pPattern = (pPatte ~= nil and pPatte or " ")
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Tae,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Tae, cap)
- end
- return Tae
- end
- function wdos.writeOs(txt,ret)
- term.setTextColor(wdos.oscolor)
- term.write(txt)
- if ret ~= nil then
- term.setTextColor(ret)
- end
- end
- function wdos.printOs(txt,ret)
- wdos.writeOs(txt,ret)
- print("")
- end
- function wdos.listSelector(list,msg)
- if type(list) ~= "table" then
- error("Input to wdos.listSelector is not a table!")
- end
- wdos.printOs(msg)
- for k,v in pairs(list) do
- wdos.writeOs(k..". ",colors.white)
- write(v)
- end
- local o = "0"
- repeat
- wdos.writeOs("> ",colors.white)
- o = read()
- until tonumber(o) >= 1 and tonumber(o) <= #tab
- end
- function wdos.defaultCmdHandler(cmd)
- local args = wdos.split(cmd)
- if #args < 1 then
- printError("No such command.")
- end
- local tab = {}
- for i,v in pairs(fs.list(".wdos")) do
- for p,o in pairs(fs.list(".wdos/"..v)) do
- if (o == args[1]) then
- table.insert(tab,v)
- end
- end
- end
- if #tab > 1 then
- local sel = wdos.listSelector("More than one package with this command found.",tab)
- shell.run(".wdos/"..tab[sel].."/"..args[1],unpack(args,2))
- elseif #tab == 1 then
- shell.run(".wdos/"..tab[1].."/"..args[1],unpack(args,2))
- else
- printError("No such command.")
- end
- end
- function wdos.defaultShell()
- term.clear()
- term.setCursorPos(1,1)
- wdos.printOs(wdos.version)
- while true do
- wdos.writeOs("> ",colors.white)
- local cmd = read()
- wdos.defaultCmdHandler(cmd)
- end
- end
- function wdos.init()
- local tab = {}
- if fs.exists(".wdos") == false then
- fs.makeDir(".wdos")
- fs.makeDir(".wdos/default/")
- for k,v in pairs(wdos.defaultModules) do
- local f = fs.open(".wdos/default/"..k,"w")
- f.write(v)
- f.close()
- end
- end
- for i,v in pairs(fs.list(".wdos")) do
- for p,o in pairs(fs.list(".wdos/"..v)) do
- if (o == "shell") then
- table.insert(tab,v)
- end
- end
- end
- if #tab > 1 then
- local sel = wdos.listSelector("More than one shell found.",tab)
- shell.run(".wdos/"..tab[sel].."/shell",unpack(args,2))
- elseif #tab == 1 then
- shell.run(".wdos/"..tab[1].."/shell",unpack(args,2))
- else
- wdos.defaultShell()
- end
- end
- wdos.init()
Advertisement
Add Comment
Please, Sign In to add comment