largeNumberGoeshere

refresh.lua

Apr 18th, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. local defaultSlot  = 1
  2.  
  3. local floppySlot = 15
  4. local driveSlot = floppySlot + 1
  5.  
  6. local placeDriveInDirection = turtle.placeUp
  7. local insertDiskInDirection = turtle.dropUp
  8. local removeDriveInDirection= turtle.digUp
  9. local driveDirection = "top"
  10.  
  11. local tmpFolder = "/tmp/disk/"
  12.  
  13. local doNotWarnParam = "--nowarn"
  14. local silent = "--silent"
  15.  
  16. --arg[1] = doNotWarnParam
  17. --arg[2] = silent
  18.  
  19. ---
  20.  
  21. function withSlotDo(slot, toDo)
  22.     turtle.select(slot)
  23.     toDo()
  24.     turtle.select(defaultSlot)
  25. end
  26.  
  27. function placeDrive()
  28.     withSlotDo(
  29.                 driveSlot,
  30.        
  31.                 function()
  32.             placeDriveInDirection()
  33.         end
  34.     )
  35. end
  36.  
  37. function insertDisk()
  38.     withSlotDo(
  39.         floppySlot,
  40.         function()
  41.             insertDiskInDirection()
  42.         end
  43.     )
  44. end
  45.  
  46. function getSourceFile()
  47.     return shell.getRunningProgram()
  48. end
  49.  
  50. function getSourceDir()
  51.     return fs.getDir(getSourceFile())
  52. end
  53.  
  54. function getSourceRoot()
  55.     local driveSide = fs.getDrive(getSourceDir())
  56.     local per = peripheral.wrap(driveSide)
  57.     local path = per.getMountPath()
  58.     return path
  59. end
  60.  
  61. function getDriveRoot()
  62.  
  63.     local drive =  peripheral.wrap(driveDirection)
  64.     --print(drive)
  65.     local root = drive.getMountPath()
  66.     --print(root)
  67.     return root
  68.    
  69. end
  70.  
  71. function getDiskName()
  72.     local drive = peripheral.wrap(driveDirection)
  73.     local name = drive.getDiskLabel()
  74.     return name
  75. end
  76.  
  77. function getDiskID()
  78.         local drive = peripheral.wrap(driveDirection)
  79.         local ID = drive.getDiskID()
  80.         return ID
  81. end
  82.  
  83.  
  84.  
  85. function cpDisk()
  86.  
  87.     root = getDriveRoot()
  88.  
  89.     -- local copyCmd = "/rom/programs/copy.lua"
  90.     -- local mkdirCmd = "/rom/programs/mkdir.lua"
  91.     -- local gap = " "
  92.    
  93.     -- local toDo1 = mkdirCmd .. gap .. tmpFolder
  94.     -- local toDo2 = copyCmd.. gap  ..root.. gap..tmpFolder
  95.    
  96.     -- print(toDo1)
  97.     -- print(toDo2)
  98.    
  99.     -- shell.execute(toDo1)
  100.     -- shell.execute(toDo2)
  101.    
  102.     fs.delete(tmpFolder)
  103.     fs.copy(root,tmpFolder)
  104. end
  105.  
  106. function removeDrive()
  107.     withSlotDo(floppySlot,
  108.     function()
  109.         removeDriveInDirection()
  110.     end
  111.     )
  112. end
  113.  
  114. function prompt(msg)
  115.     write(msg..": ")
  116.     return read()
  117. end
  118.  
  119. function warnUser()
  120.     local gap = " "
  121.     -- warn user and allow them to cancel
  122.     print("")
  123.     print(">>>  WARNING  <<<")
  124.     print("WILL DELETE tmp/disk!")
  125.     print("and overrite it with the contents of the new disk")
  126.     --print("DISK: "..getDriveRoot()..gap..getDiskName()..gap..getDiskID()..gap..getDiskLabel())
  127.     print()
  128.     ready = prompt("are you sure you want to continue? If so then type yes")
  129.     print(ready)
  130.  
  131.     if ready == "yes" then
  132.         -- continue
  133.     else
  134.         error("user has declined")
  135.     end
  136.    
  137. end
  138.  
  139. function showInfo()
  140.     print("Please insert a floppy into slot "..floppySlot.. " and a disk drive into "..driveSlot)
  141.     prompt("Press enter when done")
  142. end
  143.  
  144. function success()
  145.     print("Success! floppy disk copied to "..tmpFolder)
  146.    
  147. end
  148.  
  149. if arg[1] ~= doNotWarnParam then
  150.     warnUser()
  151.     showInfo()
  152. end
  153. placeDrive()
  154. insertDisk()
  155. cpDisk()
  156. removeDrive()
  157.  
  158. if arg[2] ~=silent then
  159.     success()
  160. end
  161. if arg[1] ~= doNotWarnParam then
  162.     print("Please do NOT edit this folder directly, it will be deleted on next run")
  163. end
  164.  
Add Comment
Please, Sign In to add comment