svdragster

scan

Mar 16th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. problem = 0
  2. art = ""
  3. contain = ""
  4. number = 1
  5.  
  6. local tFiles = {}
  7. probinhalt = {}
  8. infectinhalt = {}
  9.  
  10. logfilename = "/PSAV/reports/log"..os.day().."."..os.time()..".log"
  11. file = fs.open("/PSAV/reports/logs.txt", "a")
  12. file.writeLine(logfilename)
  13. file.close()
  14.  
  15. function report(dateipath, art, contain)
  16.   local str = os.day().."\t"..textutils.formatTime(os.time(), true).."\t"..art.."\t"..dateipath.."\t"..contain
  17.   file = fs.open(logfilename, "a")
  18.   file.writeLine(str)
  19.   file.close()
  20.   number = number + 1
  21. end
  22.  
  23. function replaceLine( path, line, text )
  24.     if not tFiles[path] then return false end
  25.     tFiles[path][line] = text
  26.     return writeTable(path, tFiles[path] )
  27. end
  28.  
  29. function check(datei)
  30.    term.setTextColour(colors.white)
  31.    write(datei.." ")
  32.    if fs.isDir(datei) then
  33.       term.setTextColour(colors.green)
  34.       print("\(DIR\)")
  35.    else
  36.       term.setTextColour( colors.orange )
  37.       print("")
  38.       local f = io.open(datei, "r")
  39.       local data = f:read("*a")
  40.       f:close()
  41.  
  42.       term.setTextColour(colors.white)
  43.       for i = 1, #probinhalt do
  44.         if data:find (probinhalt[i]) then
  45.            problem = problem + 1
  46.            term.setTextColour(colors.red)
  47.            print("> Found a problem in "..datei.."!")
  48.            report(datei, "problem", probinhalt[i])
  49.         else
  50.            report(datei, "nothing", probinhalt[i])
  51.            term.setTextColour(colors.lime)
  52.            print("No problem in "..datei)
  53.         end  
  54.         term.setTextColour( colors.white )
  55.       end
  56.      
  57.    end
  58.  
  59.   term.setTextColour(colors.red)
  60.   if problem > 1 or problem == 0 then
  61.     print("Found "..problem.." problems!")
  62.     term.setTextColour(colors.white)
  63.   else
  64.     print("Found "..problem.." problem!")
  65.     term.setTextColour(colors.white)
  66.   end
  67. end
  68.  
  69.  
  70.  
  71. function ReadDir(dir)
  72.  local dateien = fs.list(dir)
  73.  for i = 1, #dateien do
  74.   local path = fs.combine(dir, dateien[i])
  75.   if fs.isDir(path) then
  76.     if (dateien[i] ~= "rom") and (dateien[i] ~= "PSAV") and (dateien[i] ~= "PSAVbackup") then
  77.       ReadDir(path)
  78.     end
  79.   end
  80.   check(path)
  81.  end
  82. end
  83.  
  84. --------
  85. --MAIN--
  86. --------
  87. --Liest mgl. probleme ein
  88. probtxt = fs.open("/PSAV/problems.txt", "r")
  89. zeile = probtxt.readLine()
  90. repeat
  91.   table.insert(probinhalt, zeile)
  92.   zeile = probtxt.readLine()
  93. until zeile == nil
  94.  
  95.  
  96. term.clear()
  97. term.setCursorPos(1,1)
  98. ReadDir("/")
  99.  
  100. --nochmal Problem Anzahl anzeigen...
  101. if problem == 1 then
  102.   print(problem.." problem found!")
  103. else
  104.   print(problem.." problems found!")
  105. end
  106.  
  107. term.setTextColour( colors.yellow )
  108. print("Waiting for Mouseclick")
  109. os.pullEvent("mouse_click")
  110. shell.run("/PSAV/details")
Advertisement
Add Comment
Please, Sign In to add comment