Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local defaultSlot = 1
- local floppySlot = 15
- local driveSlot = floppySlot + 1
- local placeDriveInDirection = turtle.placeUp
- local insertDiskInDirection = turtle.dropUp
- local removeDriveInDirection= turtle.digUp
- local driveDirection = "top"
- local tmpFolder = "/tmp/disk/"
- local doNotWarnParam = "--nowarn"
- local silent = "--silent"
- --arg[1] = doNotWarnParam
- --arg[2] = silent
- ---
- function withSlotDo(slot, toDo)
- turtle.select(slot)
- toDo()
- turtle.select(defaultSlot)
- end
- function placeDrive()
- withSlotDo(
- driveSlot,
- function()
- placeDriveInDirection()
- end
- )
- end
- function insertDisk()
- withSlotDo(
- floppySlot,
- function()
- insertDiskInDirection()
- end
- )
- end
- function getSourceFile()
- return shell.getRunningProgram()
- end
- function getSourceDir()
- return fs.getDir(getSourceFile())
- end
- function getSourceRoot()
- local driveSide = fs.getDrive(getSourceDir())
- local per = peripheral.wrap(driveSide)
- local path = per.getMountPath()
- return path
- end
- function getDriveRoot()
- local drive = peripheral.wrap(driveDirection)
- --print(drive)
- local root = drive.getMountPath()
- --print(root)
- return root
- end
- function getDiskName()
- local drive = peripheral.wrap(driveDirection)
- local name = drive.getDiskLabel()
- return name
- end
- function getDiskID()
- local drive = peripheral.wrap(driveDirection)
- local ID = drive.getDiskID()
- return ID
- end
- function cpDisk()
- root = getDriveRoot()
- -- local copyCmd = "/rom/programs/copy.lua"
- -- local mkdirCmd = "/rom/programs/mkdir.lua"
- -- local gap = " "
- -- local toDo1 = mkdirCmd .. gap .. tmpFolder
- -- local toDo2 = copyCmd.. gap ..root.. gap..tmpFolder
- -- print(toDo1)
- -- print(toDo2)
- -- shell.execute(toDo1)
- -- shell.execute(toDo2)
- fs.delete(tmpFolder)
- fs.copy(root,tmpFolder)
- end
- function removeDrive()
- withSlotDo(floppySlot,
- function()
- removeDriveInDirection()
- end
- )
- end
- function prompt(msg)
- write(msg..": ")
- return read()
- end
- function warnUser()
- local gap = " "
- -- warn user and allow them to cancel
- print("")
- print(">>> WARNING <<<")
- print("WILL DELETE tmp/disk!")
- print("and overrite it with the contents of the new disk")
- --print("DISK: "..getDriveRoot()..gap..getDiskName()..gap..getDiskID()..gap..getDiskLabel())
- print()
- ready = prompt("are you sure you want to continue? If so then type yes")
- print(ready)
- if ready == "yes" then
- -- continue
- else
- error("user has declined")
- end
- end
- function showInfo()
- print("Please insert a floppy into slot "..floppySlot.. " and a disk drive into "..driveSlot)
- prompt("Press enter when done")
- end
- function success()
- print("Success! floppy disk copied to "..tmpFolder)
- end
- if arg[1] ~= doNotWarnParam then
- warnUser()
- showInfo()
- end
- placeDrive()
- insertDisk()
- cpDisk()
- removeDrive()
- if arg[2] ~=silent then
- success()
- end
- if arg[1] ~= doNotWarnParam then
- print("Please do NOT edit this folder directly, it will be deleted on next run")
- end
Add Comment
Please, Sign In to add comment