fork download
  1. local cmp = require("component")
  2. local srl = require("serialization")
  3. local fs = require("filesystem")
  4. local sh = require("shell")
  5. local unicode = require("unicode")
  6. local term = require("term")
  7. local event = require("event")
  8.  
  9. local function write(quickfilename, cardname)
  10. if not cmp.isAvailable("OSCardWriter") then
  11. io.stderr:write("Отсуствует записывающее устройство.")
  12. return
  13. end
  14. if quickfilename then
  15. filename = quickfilename
  16. end
  17. local fileRAW = {}
  18. local writer = cmp.OSCardWriter
  19. local function askReadFrom()
  20. io.write("Введите имя файла: ")
  21. filename = term.read()
  22. filename = unicode.sub(filename, 1, -2)
  23. end
  24. if not quickfilename then
  25. askReadFrom()
  26. end
  27. for line in io.lines(filename) do
  28. table.insert(fileRAW, line)
  29. end
  30. file = srl.serialize(fileRAW)
  31. if unicode.len(file) > 128 then
  32. io.stderr:write("Превышено ограничение по размеру файла.")
  33. return
  34. end
  35. if cardname then
  36. writer.write(file, cardname)
  37. else
  38. writer.write(file)
  39. end
  40. io.write("Карта записана успешно!\n")
  41. end
  42.  
  43. local function read(quickfilename)
  44. if not cmp.isAvailable("OSMagReader") then
  45. io.stderr:write("Отсуствует картридер.")
  46. return
  47. end
  48. if quickfilename then
  49. saveto=quickfilename
  50. end
  51. io.write("Проведите картой...")
  52. _, _, _, dataRAW = event.pull("magData")
  53. io.write(" ОК!\n")
  54. local data = {}
  55. data = srl.unserialize(dataRAW)
  56. local function askSaveTo()
  57. io.write("Куда сохранить файл? ")
  58. saveto = term.read()
  59. saveto = unicode.sub(saveto, 1, -2)
  60. if fs.exists(saveto) then
  61. io.stderr:write("Файл существует. Введите другое имя.\n")
  62. askSaveTo()
  63. end
  64. end
  65. if not quickfilename then
  66. askSaveTo()
  67. end
  68. local save = io.open(saveto, "w")
  69. for _, dataFresh in pairs(data) do
  70. save:write(dataFresh.."\n")
  71. end
  72. save:flush()
  73. print("Файл сохранён!")
  74. end
  75.  
  76. local function printUsage()
  77. io.write("Использование: card <-rw> [файл] [имя]\n")
  78. io.write(" r: расшифровать данные с карты\n")
  79. io.write(" w: зашифровать данные на карту\n")
  80. end
  81.  
  82. local args, options = sh.parse(...)
  83. if options.r then
  84. if args[1] then
  85. read(args[1])
  86. else
  87. read()
  88. end
  89. elseif options.w then
  90. if args[1] and args[2] then
  91. write(args[1], args[2])
  92. elseif args[1] and not args[2] then
  93. write(args[1])
  94. else
  95. write()
  96. end
  97. else
  98. printUsage()
  99. end
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
local cmp = require("component")
^
Main.java:70: error: illegal '.'
    save:write(dataFresh.."\n")
                         ^
2 errors
stdout
Standard output is empty