Advertisement
ecco7777

CC Diskmanager

Oct 4th, 2020 (edited)
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. function wrapPs(peripheralName)
  2.     periTab = {}
  3.     sideTab = {}
  4.     if peripheralName == nil then
  5.         print("Fehler")
  6.     end
  7.     local peripherals = peripheral.getNames()
  8.     local i2 = 1
  9.     for i = 1, #peripherals do
  10.         if peripheral.getType(peripherals[i]) == peripheralName then
  11.             periTab[i2] = peripheral.wrap(peripherals[i])
  12.             sideTab[i2] = peripherals[i]
  13.             i2 = i2 + 1
  14.         end
  15.     end
  16.     if periTab ~= {} then
  17.         return periTab, sideTab
  18.     else
  19.         return nil
  20.     end
  21.  
  22.     function getPSide(peripheralName)
  23.         if peripheralName == nil then
  24.             print("Fehler")
  25.         end
  26.         local peripherals = peripheral.getNames()
  27.         local i = 1
  28.         while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
  29.             i = i + 1
  30.         end
  31.         if peripheral.getType(peripherals[i]) == peripheralName then
  32.             return peripherals[i]
  33.         else
  34.             return nil
  35.         end
  36.     end
  37. end
  38.  
  39. args={...}
  40. ds,dss=wrapPs("drive")
  41.  
  42. function getDriveData()
  43. driveData={}
  44.     for i=1, #ds do
  45.         data={}
  46.         data["dID"]=ds[i].getDiskID()
  47.         data["dLabel"]=ds[i].getDiskLabel()
  48.         data["side"]=dss[i]
  49.         data["path"]=ds[i].getMountPath()
  50.             if data.path~=nil then
  51.                 data["size"]=fs.getFreeSpace(data["path"])
  52.                 data["files"]=fs.list(data["path"])
  53.             end
  54.         data["diskPresent"]=ds[i].isDiskPresent()
  55.         data["hasAudio"]=ds[i].hasAudio()
  56.         data["audioTitle"]=ds[i].getAudioTitle()
  57.        
  58.         table.insert(driveData,data)
  59.     end
  60.     return driveData
  61. end
  62.  
  63. function listAllFiles()
  64.     dd=getDriveData()
  65.     files=""
  66.     for i=1, #dd do
  67.         if dd[i].path~=nil then
  68.             for i2=1, #dd[i]["files"] do
  69.                 files=files..", "..dd[i].path.."/"..dd[i].files[i2]
  70.             end
  71.         end
  72.     end
  73.     print(files)
  74. end
  75.  
  76. function listAudioTitles()
  77.     dd=getDriveData()
  78.     files=""
  79.     for i=1, #dd do
  80.         if dd[i]["hasAudio"] then
  81.             files=files..", "..dd[i]["side"]..":"..dd[i]["audioTitle"]
  82.         end
  83.     end
  84.     print(files)
  85. end
  86.  
  87. function listAllFilesDetail()
  88.     dd=getDriveData()
  89.     files=""
  90.     for i=1, #dd do
  91.         if dd[i].path~=nil then
  92.             for i2=1, #dd[i]["files"] do
  93.                 files=files..", "..dd[i].side..":"..dd[i].path.."/"..dd[i].files[i2]
  94.             end
  95.         end
  96.     end
  97.     print(files)
  98. end
  99.  
  100. function main()
  101.     if args[1]==nil then
  102.         print("ls -> list Files")
  103.         print("lsa -> list Details")
  104.         print("lsm -> list music")
  105.     end
  106.     if args[1]=="ls" or args[1]=="dir" then
  107.         listAllFiles()
  108.     end
  109.     if args[1]=="lsa" then
  110.         listAllFilesDetail()
  111.     end
  112.     if args[1]=="lsm" or args[1]=="dirm" then
  113.         listAudioTitles()
  114.     end
  115. end
  116. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement