Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[----------------------------------------------Check for EU
- if not require("filesystem").exists("/lib/ExtraUtilits.lua") or require("ExtraUtilits").version < 1.7 then
- require("component").gpu.set(1, 1, "You don'thave ExtraUtilits library or version is lower 1.7 to run this program. Install now?[y/n](internet card required)")
- if require("io").read() == "y" then
- print("downloading ExtraUtilits...")
- local internet = require("internet")
- local req = internet.request("http://pastebin.com/raw/474MKXJZ")
- local text = ""
- for line in req.read do
- text = text .. line
- end
- local file = require("io").open("/lib/ExtraUtilits.lua", "w")
- file:write(text)
- file:close()
- print("rebooting...")
- require("computer").shutdown(true)
- else
- os.exit()
- end
- end
- ]]
- ------------------------------------------------Defines
- local EU = require("ExtraUtilits")
- local shell = require("shell")
- local term = require("term")
- local gpu = require("component").gpu
- local unicode = require("unicode")
- local computer = require("computer")
- local fs = require("filesystem")
- local io = require("io")
- local event = require("event")
- local args = shell.parse(...)
- local path = ""
- local buttons = {}
- local list = {}
- local sys = 0
- local changePath = function() end
- local colors = {
- ["lua"] = 0x00ff00,
- ["directory"] = 0x008cff,
- ["cfg"] = 0xff841f,
- ["dfpwm"] = 0xff00ff,
- ["default"] = 0xffffff,
- ["bios"] = 0xccaa87,
- ["rec"] = 0x87c3ff
- }
- local formats = {
- ["lua"] = "default",
- ["bios"] = "/bios.lua",
- ["rec"] = "/play.lua"
- }
- ------------------------------------------------Local functions
- local function comp_shell()
- local command = EU.ReadyUtilits.WFUIV2(64, 22, 30, "computer shell")
- command = "computer." .. command
- local func, reason = load(command)
- if func then
- local result, reason = xpcall(func, debug.traceback)
- end
- end
- local function alt()
- local ok = false
- local evt, _, key1, key2
- repeat
- evt, _, key1, key2 = computer.pullSignal()
- if evt == "key_down" or evt == "key_up" then ok = true end
- until ok
- if evt == key_up then
- return false
- elseif evt == "key_down" then
- if key1 == 99 and key2 == 46 then
- comp_shell()
- end
- end
- end
- local hotKeys = {
- {key1 = 0, key2 = 56, func = alt}
- }
- local w, h = gpu.getResolution()
- local ploadFile = function(name, args)
- local args = args or {}
- local func, reason = loadfile(name)
- local rs
- local err = false
- if not func then
- err = true
- rs = reason
- else
- func = function() func(table.unpack(args)) end
- local result, reason = xpcall(func, debug.traceback)
- if not result and reason then
- err = true
- rs = reason
- else
- local text = "[press any key to continue]"
- gpu.setBackground(0x323232)
- gpu.setForeground(0xffffff)
- term.clear()
- local w, h = gpu.getResolution()
- gpu.set(w / 2 - #text / 2, h / 2, text)
- repeat until computer.pullSignal() == "key_down"
- end
- end
- --[[if err then
- local text = "Error with running file:"
- gpu.setBackground(0x323232)
- gpu.setForeground(0xff0000)
- term.clear()
- local w, h = gpu.getResolution()
- local lines = {}
- local brk = false
- repeat
- for i = 1, #rs do
- local symbol = rs:sub(i, i)
- if i == #rs then
- brk = true
- break
- elseif symbol == "\n" then
- lines[#lines+1] = rs:sub(1, i - 1)
- rs = lines[#lines]
- break
- else
- lines[#lines] = lines[#lines] or "" .. rs:sub(i, i)
- end
- end
- until brk
- gpu.set(w / 2 - #text / 2, h / 2 - #lines / 2 - 1, text)
- for i = 1, #lines do
- local line = lines[i]
- gpu.set(w / 2 - #line / 2, h / 2 - #lines / 2 + i, line)
- end
- event.pull("key_down")
- end]]
- gpu.setBackground(0x323232)
- term.clear()
- EU.draw(buttons)
- changePath()
- end
- local function onKey(ev)
- local _, _, key1, key2 = table.unpack(ev)
- for i in pairs(hotKeys) do
- local hotKey = hotKeys[i]
- if key1 == hotKey.key1 then
- if hotKey.key2 == nil or hotKey.key2 == key2 then
- computer.beep(1200, 0.1)
- hotKey.func()
- end
- end
- end
- end
- local function press(button, color, timeout)
- if not timeout then timeout = 0.2 end
- local dColor = button[5]
- button[5] = color
- EU.draw({button})
- os.sleep(timeout)
- button[5] = dColor
- EU.draw({button})
- end
- local function sysMenu()
- press(buttons[sys], 0x323232)
- local menu = {}
- local function top()
- press(menu[1], 0xff7a7a)
- menu.close = true
- end
- local function shutdown()
- press(menu[2], 0x999999)
- computer.shutdown()
- end
- local function reboot()
- press(menu[3], 0x999999)
- local file = io.open("/Autorun.lua", "w")
- local code = [[
- require("filesystem").remove("/Autorun.lua")
- os.sleep(1)
- loadfile("/finder.lua")()
- ]]
- file:write(code)
- file:close()
- computer.shutdown(true)
- end
- menu[1] = {148, 45, 10, 1, 0xff0000, 0xffffff, "System", top}
- menu[2] = {148, 46, 10, 1, 0x646464, 0x323232, "Shutdown", shutdown}
- menu[3] = {148, 47, 10, 1, 0x646464, 0x323232, "Reboot", reboot}
- EU.draw(menu)
- EU.buttonPress(menu)
- gpu.setBackground(0x323232)
- term.clear()
- changePath()
- end
- ------------------------------------------------Define main path
- if args and #args > 0 then
- path = args[1]
- else
- path = shell.resolve("")
- end
- ------------------------------------------------Main function
- local function changePath()
- gpu.setBackground(0x323232)
- term.clear()
- buttons = {}
- list = EU.list(path)
- for i = 1, #list do
- local function showMenu()
- press(buttons[i], 0x646464)
- local lw = unicode.wlen(list[i])
- local w = unicode.wlen(list[i])
- if w < 15 then w = 15 end
- local menu = {}
- local function top()
- press(menu[1], 0xff7a7a)
- menu.close = true
- end
- local function edit()
- press(menu[2], 0x999999)
- loadfile("/bin/edit.lua")(shell.resolve(path .. "/" .. list[i]))
- menu.close = true
- end
- local function remove()
- EU.screenBackup(function()
- local remButtons = {}
- press(menu[3], 0x999999)
- local function ok()
- press(remButtons[1], 0x646464)
- fs.remove(shell.resolve(path .. "/" .. list[i]))
- remButtons.close = true
- end
- local text = "do you want to remove " .. list[i] .. "?"
- gpu.setBackground(0xffffff)
- gpu.setForeground(0x646464)
- gpu.fill(160 / 2 - (#text / 2) - 1, h/2 - 1, #text + 2, 4, " ")
- gpu.set(80 - #text/2, h/2, text)
- remButtons = {
- {80 + #text/2-4, h / 2 + 2, 3, 1, 0xffffff, 0x323232, "Yes", ok},
- {80 - #text/2, h / 2 + 2, 2, 1, 0xffffff, 0x323232, "No", function() remButtons.close = true press(remButtons[2], 0x646464) end}
- }
- remButtons.eventFunc = function(ev)
- if ev[1] == "key_down" then
- if ev[3] == 13 then
- ok()
- elseif ev[3] == 9 then
- remButtons.close = true
- press(remButtons[2], 0x646464)
- end
- end
- end
- EU.draw(remButtons)
- EU.buttonPress(remButtons)
- menu.close = true
- end)
- end
- local function run_with_args()
- press(menu[4], 0x999999)
- loadfile(shell.resolve(path .. "/" .. list[i]))(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter arguments:"))
- menu.close = true
- end
- local function rename()
- press(menu[5], 0x999999)
- fs.rename(shell.resolve(path .. "/" .. list[i]), shell.resolve(path .. "/" .. EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter new file name:")))
- menu.close = true
- end
- menu[1] = {lw + 3, i, w, 1, 0xff0000, 0xffffff, list[i], top}
- menu[2] = {lw + 3, i + 1, w, 1, 0x646464, 0x323232, "edit", edit}
- menu[3] = {lw + 3, i + 2, w, 1, 0x646464, 0x323232, "remove", remove}
- menu[4] = {lw + 3, i + 3, w, 1, 0x646464, 0x323232, "run with args", run_with_args}
- menu[5] = {lw + 3, i + 4, w, 1, 0x646464, 0x323232, "rename", rename}
- EU.draw(buttons)
- EU.draw(menu, true)
- EU.buttonPress(menu)
- changePath()
- end
- local function dofile()
- local lPath
- press(buttons[i], 0x646464)
- if fs.isDirectory(list[i]) then
- path = shell.resolve(path .. "/" .. list[i])
- changePath()
- else
- local format = EU.getFormat(list[i])
- for k, v in pairs(formats) do if k == format then lPath = v end end
- end
- if not lPath then lPath = "/bin/edit.lua" end
- if lPath == "default" then ploadFile(list[i])
- else
- if fs.exists(lPath) then
- gpu.set(80, 25, lPath .. "|" .. list[i])
- os.sleep(1)
- ploadFile(lPath, {list[i]})
- end
- end
- end
- --Files buttons
- local color = colors["default"]
- local f = ""
- if fs.isDirectory(shell.resolve(path .. "/" .. list[i])) then
- color = colors["directory"]
- else
- local format = EU.getFormat(list[i])
- for k, v in pairs(colors) do if format == k then color = v end end
- end
- buttons[i] = {}
- buttons[i][1] = 1
- buttons[i][2] = i + 1
- buttons[i][3] = unicode.wlen(list[i])
- buttons[i][4] = 1
- buttons[i][5] = 0x323232
- buttons[i][6] = color
- buttons[i][7] = list[i]
- buttons[i][8] = dofile
- buttons[i][10] = showMenu
- end
- --Interface
- local now = #buttons+1
- local function close() f_close = true gpu.setBackground(0x000000) gpu.setForeground(0xffffff) term.clear() os.exit() end
- buttons[now] = {160, 1, 1, 1, 0x161616, 0xffffff, "X", close}
- local now = #buttons+1
- local function enterPath() path = shell.resolve(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter new path:")) changePath() EU.buttonPress(buttons) end
- buttons[now] = {3, 1, 157, 1, 0x161616, 0x00ffff, path, enterPath}
- local now = #buttons+1
- function new()
- press(buttons[now], 0x999999)
- local menu = {}
- local function top()
- press(menu[1], 0xff7a7a)
- menu.close = true
- end
- local function file()
- press(menu[2], 0x646464)
- local name = shell.resolve(path .. "/" .. EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter file name:"))
- loadfile("/bin/edit.lua")(name)
- menu.close = true
- end
- local function folder()
- press(menu[3], 0x999999)
- local name = shell.resolve(path .. "/" .. EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter folder name:"))
- local result, reason = fs.makeDirectory(name)
- if not result then EU.screenBackup(function() gpu.setBackground(0x161616) gpu.setForeground(0x00ffff) gpu.set(60, 23, reason) os.sleep(1) end) end
- menu.close = true
- end
- menu[1] = {145, 2, 10, 1, 0xff0000, 0xffffff, "New", top}
- menu[2] = {145, 3, 10, 1, 0x646464, 0x323232, "file", file}
- menu[3] = {145, 4, 10, 1, 0x646464, 0x323232, "folder", folder}
- EU.draw(menu)
- EU.buttonPress(menu)
- changePath()
- end
- buttons[now] = {158, 2, 3, 1, 0x323232, 0x00ff00, "New", new}
- local now = #buttons+1
- function run() press(buttons[now], 0x646464) local name = shell.resolve(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter file name:")) local func = ploadFile(shell.resolve(path .. "/" .. name)) if func then func() end end
- buttons[now] = {158, 3, 3, 1, 0x323232, 0x00ff00, "Run", run}
- local now = #buttons+1
- function root() press(buttons[now], 0x323232) path = "/" changePath() end
- buttons[now] = {1, 1, 2, 1, 0x161616, 0x00ffff, "<<", root}
- local now = #buttons+1
- buttons[now] = {1, 50, 160, 1, 0x161616, 0x00ffff, "", function() end}
- local now = #buttons+1
- function lua() press(buttons[now], 0x646464) gpu.setBackground(0) gpu.setForeground(0xffffff) term.clear() loadfile("/bin/lua.lua")() changePath() end
- buttons[now] = {158, 4, 3, 1, 0x323232, 0x00ff00, "Lua", lua}
- local now = #buttons+1
- sys = now
- buttons[now] = {155, 50, 6, 1, 0x161616, 0xffffff, "System", sysMenu}
- buttons.eventFunc = function(ev)
- local evt, _, key1, key2 = table.unpack(ev)
- if evt == "key_down" and key1 == 23 and key2 == 17 then
- close()
- elseif unicode.char(key1) == "r" then
- changePath()
- elseif evt == "key_down" then
- onKey(ev)
- end
- end
- EU.draw(buttons)
- EU.buttonPress(buttons)
- end
- ------------------------------------------------Run
- changePath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement