svdragster

details

Mar 16th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. local lines = fileTableGet("/PSAV/reports/logs.txt", "r")
  2. logfilename = lines[#lines]
  3.  
  4.  
  5. function fileTableGet(path)
  6.     if fs.exists(path) then
  7.         local file = io.open(path, "r")
  8.         local lines = {}
  9.         local i = 1
  10.         local line = file:read("*l")
  11.         while line ~= nil do
  12.             lines[i] = line
  13.             line = file:read("*l")
  14.             i = i + 1
  15.         end
  16.         file:close()
  17.         return lines
  18.     end
  19.     return {}
  20. end
  21.  
  22. function fileLineGet(path, line)
  23.     if fs.exists(path) then
  24.         local lines = fileTableGet(path)
  25.         return lines[line]
  26.     end
  27.     return ""
  28. end
  29.  
  30. --table elemente ab index start zu string zusammenfügen
  31. function join(tbl, start)
  32.   local tmpstr = ""
  33.   for i = start, #tbl do
  34.     tmpstr = tmpstr..tbl[i].." "
  35.   end
  36.   return tmpstr
  37. end
  38.  
  39. 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
  40.  
  41.  
  42.  
  43. --Für die Ränder
  44.  
  45. function bg(pcount)
  46.     term.setBackgroundColour( colors.green )
  47.     term.clear()
  48.     term.setTextColour(colors.cyan)
  49.     term.setCursorPos(2,2)
  50.     print("PSAV - BETA")
  51.     term.setCursorPos(51,1)
  52.     term.setBackgroundColour( colors.red )
  53.     print("x")
  54.     term.setBackgroundColour( colors.green )
  55.     term.setCursorPos(37,2)
  56.     if pcount == 0 then
  57.       term.setTextColour(colors.lime)
  58.       write("Safe!")
  59.     else
  60.       term.setTextColour(colors.orange)
  61.       write("Problems!\(")
  62.       write(pcount)
  63.       write("\)")
  64.     end
  65.     term.setTextColour(colors.white)
  66. end
  67.  
  68. function checkxy(x, y, cx1, cx2, cy)
  69.   local res = false
  70.   if y == cy then
  71.     if (x >= cx1) and (x <= cx2) then
  72.       res = true
  73.     end
  74.   end
  75.   return res
  76. end
  77.  
  78. --MAIN
  79.  
  80.  
  81.  
  82. --existieren überhaupt probleme?
  83. term.setCursorPos(2,19)
  84. term.setTextColour( colors.cyan )
  85. term.setBackgroundColour( colors.yellow )
  86. print("okay")
  87. term.setCursorPos(2,15)
  88. print("<-")
  89. term.setCursorPos(7,15)
  90. print("->")
  91.  
  92. nummer = 1
  93. problemcount = 0
  94. linecount = 0
  95. okay = false
  96. line = "blah"
  97. while line ~= nil do
  98.   line = fileLineGet(logfilename, linecount + 1)
  99.   if line ~= nil then
  100.     linecount = linecount + 1
  101.     res = split(line, "\t")
  102.     if res[3] == "problem" then
  103.       problemcount = problemcount + 1
  104.     end
  105.   end
  106. end
  107.  
  108. nummer = 1
  109.  
  110. while okay == false do
  111.   bg(problemcount)
  112.   term.setTextColour( colors.cyan )
  113.   term.setBackgroundColour( colors.yellow )
  114.   term.setCursorPos(2,19)
  115.   write("okay")
  116.   if problemcount > 0 then
  117.     if nummer > 1 then
  118.       term.setCursorPos(2,15)
  119.       write("<-")
  120.     end
  121.     if nummer < linecount then
  122.       term.setCursorPos(7,15)
  123.       write("->")
  124.     end
  125.     term.setTextColour( colors.white )
  126.     term.setBackgroundColour( colors.green )
  127.     term.setCursorPos(50,19)
  128.     write(nummer)
  129.     term.setCursorPos(4,4)
  130.     str = fileLineGet(logfilename, nummer)
  131.     res = split(str, "\t")
  132.     program = split(res[4], " ")
  133.     term.setTextColour( colors.white )
  134.     print("SCAN REPORT:")
  135.     if res[3] == "problem" then
  136.       term.setTextColour( colors.orange )
  137.       print("Found "..res[3].." in file '"..res[4].."'")
  138.       print("Contains: '"..res[5].."'")
  139.     else
  140.       print("File '"..res[4].."' okay")  
  141.     end
  142.   else
  143.     term.setTextColour( colors.lime )
  144.     print("Recently PSAV didn't report any problems or infections!")
  145.   end
  146.  
  147.  
  148.   event, knopf, x, y = os.pullEvent("mouse_click")
  149. -- [okay] Knopf
  150.   if checkxy(x, y, 2, 5, 19) then
  151.     okay = true
  152.     shell.run("/PSAV/psav")
  153.   end
  154. -- [X] Knopf
  155.   if checkxy(x, y, 51, 51, 1) then
  156.     okay = true
  157.     shell.run("shell")
  158.   end
  159.  
  160.   if problemcount > 0 then
  161. -- [<-] Knopf
  162.     if nummer > 1 and checkxy(x, y, 2, 3, 15) then
  163.       nummer = nummer - 1
  164.       okay = false
  165.       end
  166. -- [->] Knopf
  167.     if nummer < linecount and checkxy(x, y, 7, 8, 15) then
  168.       nummer = nummer + 1
  169.       okay = false
  170.     end
  171.   end
  172.  
  173. end
  174.  
  175.  
  176.  
  177. shell.run("/PSAV/PSAV")
Advertisement
Add Comment
Please, Sign In to add comment