Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lines = fileTableGet("/PSAV/reports/logs.txt", "r")
- logfilename = lines[#lines]
- function fileTableGet(path)
- if fs.exists(path) then
- local file = io.open(path, "r")
- local lines = {}
- local i = 1
- local line = file:read("*l")
- while line ~= nil do
- lines[i] = line
- line = file:read("*l")
- i = i + 1
- end
- file:close()
- return lines
- end
- return {}
- end
- function fileLineGet(path, line)
- if fs.exists(path) then
- local lines = fileTableGet(path)
- return lines[line]
- end
- return ""
- end
- --table elemente ab index start zu string zusammenfügen
- function join(tbl, start)
- local tmpstr = ""
- for i = start, #tbl do
- tmpstr = tmpstr..tbl[i].." "
- end
- return tmpstr
- end
- local split = function(str, pat) local t = {} local fpat = "(.-)"..pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
- --Für die Ränder
- function bg(pcount)
- term.setBackgroundColour( colors.green )
- term.clear()
- term.setTextColour(colors.cyan)
- term.setCursorPos(2,2)
- print("PSAV - BETA")
- term.setCursorPos(51,1)
- term.setBackgroundColour( colors.red )
- print("x")
- term.setBackgroundColour( colors.green )
- term.setCursorPos(37,2)
- if pcount == 0 then
- term.setTextColour(colors.lime)
- write("Safe!")
- else
- term.setTextColour(colors.orange)
- write("Problems!\(")
- write(pcount)
- write("\)")
- end
- term.setTextColour(colors.white)
- end
- function checkxy(x, y, cx1, cx2, cy)
- local res = false
- if y == cy then
- if (x >= cx1) and (x <= cx2) then
- res = true
- end
- end
- return res
- end
- --MAIN
- --existieren überhaupt probleme?
- term.setCursorPos(2,19)
- term.setTextColour( colors.cyan )
- term.setBackgroundColour( colors.yellow )
- print("okay")
- term.setCursorPos(2,15)
- print("<-")
- term.setCursorPos(7,15)
- print("->")
- nummer = 1
- problemcount = 0
- linecount = 0
- okay = false
- line = "blah"
- while line ~= nil do
- line = fileLineGet(logfilename, linecount + 1)
- if line ~= nil then
- linecount = linecount + 1
- res = split(line, "\t")
- if res[3] == "problem" then
- problemcount = problemcount + 1
- end
- end
- end
- nummer = 1
- while okay == false do
- bg(problemcount)
- term.setTextColour( colors.cyan )
- term.setBackgroundColour( colors.yellow )
- term.setCursorPos(2,19)
- write("okay")
- if problemcount > 0 then
- if nummer > 1 then
- term.setCursorPos(2,15)
- write("<-")
- end
- if nummer < linecount then
- term.setCursorPos(7,15)
- write("->")
- end
- term.setTextColour( colors.white )
- term.setBackgroundColour( colors.green )
- term.setCursorPos(50,19)
- write(nummer)
- term.setCursorPos(4,4)
- str = fileLineGet(logfilename, nummer)
- res = split(str, "\t")
- program = split(res[4], " ")
- term.setTextColour( colors.white )
- print("SCAN REPORT:")
- if res[3] == "problem" then
- term.setTextColour( colors.orange )
- print("Found "..res[3].." in file '"..res[4].."'")
- print("Contains: '"..res[5].."'")
- else
- print("File '"..res[4].."' okay")
- end
- else
- term.setTextColour( colors.lime )
- print("Recently PSAV didn't report any problems or infections!")
- end
- event, knopf, x, y = os.pullEvent("mouse_click")
- -- [okay] Knopf
- if checkxy(x, y, 2, 5, 19) then
- okay = true
- shell.run("/PSAV/psav")
- end
- -- [X] Knopf
- if checkxy(x, y, 51, 51, 1) then
- okay = true
- shell.run("shell")
- end
- if problemcount > 0 then
- -- [<-] Knopf
- if nummer > 1 and checkxy(x, y, 2, 3, 15) then
- nummer = nummer - 1
- okay = false
- end
- -- [->] Knopf
- if nummer < linecount and checkxy(x, y, 7, 8, 15) then
- nummer = nummer + 1
- okay = false
- end
- end
- end
- shell.run("/PSAV/PSAV")
Advertisement
Add Comment
Please, Sign In to add comment