Advertisement
Guest User

autodisk

a guest
Jun 26th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. ASK = true -- При false пишет все с адреса DISKS, при true спрашивает субфолдер
  2. DISKS = "/ft/" -- Абсолютный адрес фолдера с образами дисков
  3. SLEEP_TIME = 10 -- время между проверками новой дискеты в режиме ASK = false
  4. HOPPER_SIDE = 4 -- сторона провода к воронке от ПК/блока Redstone IO
  5. CHANGE_RES = true -- позволить изменять разрешение экрана
  6.  
  7. fs = require("filesystem")
  8. table = require("table")
  9. os = require("os")
  10. shell = require("shell")
  11. event = require("event")
  12. component = require("component")
  13. rs = component.redstone
  14. if ASK == true then
  15.  gpu = component.gpu
  16.  term = require("term")
  17.  isolist = {}
  18.  for list in fs.list(DISKS) do
  19.   table.insert(isolist,list)
  20.  end
  21.  resx, resy = gpu.getResolution()
  22. end
  23. filesystems = {}
  24. for list in fs.list("/mnt") do
  25.  table.insert(filesystems, list)
  26. end
  27.  
  28. function findNewDisk()
  29.  newfslist = {}
  30.  for list in fs.list("/mnt") do
  31.   table.insert(newfslist, list)
  32.  end
  33.  for i=1,#newfslist,1 do
  34.   if newfslist[i] ~= filesystems[i] then
  35.    return newfslist[i]
  36.   end
  37.  end
  38.  return false
  39. end
  40.  
  41. function drawIface(redid)
  42.  term.clear()
  43.  for i=1,#isolist,1 do
  44.   if redid == i then
  45.    gpu.setBackground(0xFF0000)
  46.   else
  47.    gpu.setBackground(0x0000FF)
  48.   end
  49.   textlen = string.len(isolist[i]) - 1
  50.   text = string.sub(isolist[i],1,textlen)
  51.   if string.sub(text,1,1) == "_" then
  52.    text = string.sub(text,2,textlen)
  53.    textlen = textlen - 1
  54.   end
  55.   startx = ((resx - textlen) / 2) + 1
  56.   starty = i * 2
  57.   if starty > resy then
  58.    print("Слишком много субфолдеров или слишком мало экранного места")
  59.    error()
  60.   end
  61.   gpu.set(startx,starty,text)
  62.   gpu.setBackground(0x000000)
  63.  end
  64. end
  65.  
  66. function burnDisk(disk,addr)
  67.  addr = DISKS..addr -- теперь абсолютный
  68.  if disk == false then return false end
  69.  shell.setWorkingDirectory("/mnt/"..disk)
  70.  if addr ~= DISKS.."_[EJECT]/" then
  71.   shell.execute("rm -r ./*") -- чистим дискетку
  72.   shell.execute("cp -r "..addr.."* ./")
  73.  end
  74.  rs.setOutput(HOPPER_SIDE,0)
  75.  os.sleep(0.5)
  76.  rs.setOutput(HOPPER_SIDE,15)
  77. end
  78.  
  79. rs.setOutput(HOPPER_SIDE,15)
  80. if ASK == true then
  81.  if CHANGE_RES == true then
  82.   maxlen = string.len(isolist[1]) - 1
  83.   if string.sub(isolist[1],1,1) == "_" then -- _[EJECT]/
  84.    maxlen = maxlen - 1
  85.   end
  86.   for i=1,#isolist,1 do
  87.    templen = string.len(isolist[i]) - 1
  88.    if string.sub(isolist[i],1,1) == "_" then
  89.     templen = templen - 1
  90.    end
  91.    if templen > maxlen then maxlen = templen end
  92.   end
  93.   newresx = maxlen + 2
  94.   newresy = (#isolist * 2) + 1
  95.   gpu.setResolution(newresx,newresy)
  96.   resx,resy = gpu.getResolution()
  97.  end
  98.  while true do
  99.   drawIface(99) -- чтобы точно не раскрасило ничего лишнего
  100.   _, _, _, clicky = event.pull("touch")
  101.   if clicky % 2 == 0 and clicky / 2 <= #isolist then
  102.    drawIface(clicky/2)
  103.    burnDisk(findNewDisk(),isolist[clicky/2])
  104.   end
  105.  end
  106. else
  107.  while true do
  108.   os.sleep(SLEEP_TIME)
  109.   newDisk = findNewDisk()
  110.   if newDisk ~= false then
  111.    burnDisk(newDisk,".")
  112.   end
  113.  end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement