forked from hkc/cc-stuff
Added tape cloner
This commit is contained in:
parent
0bf8549a65
commit
736d763b64
|
@ -0,0 +1,84 @@
|
|||
local args = { ... }
|
||||
|
||||
if #args == 0 then
|
||||
print("Usage: tape-rip [-S] [source-drive] [dst-drive]")
|
||||
print(" -S don't seek to the beginning of destination drive")
|
||||
end
|
||||
|
||||
local seekToStart = true
|
||||
if args[1] == "-S" then
|
||||
seekToStart= false
|
||||
table.remove(args, 1)
|
||||
end
|
||||
|
||||
local function textProgress(p, c1, c2, fmt, ...)
|
||||
p = math.min(p, 1)
|
||||
local tw = term.getSize()
|
||||
local str = string.format(fmt, ...)
|
||||
local w1 = math.ceil(p * tw)
|
||||
local w2 = tw - w1
|
||||
|
||||
local bg = term.getBackgroundColor()
|
||||
|
||||
term.setBackgroundColor(c1)
|
||||
term.write(str:sub(1, w1))
|
||||
local rem = w1 - #str
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(c2)
|
||||
term.write(str:sub(w1 + 1, w1 + w2))
|
||||
|
||||
rem = math.min(tw - #str, w2)
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(bg)
|
||||
end
|
||||
|
||||
local src = peripheral.wrap(args[1])
|
||||
local dst = peripheral.wrap(args[2])
|
||||
|
||||
local failure = false
|
||||
if not src then
|
||||
printError("Source drive not found")
|
||||
failure = true
|
||||
end
|
||||
|
||||
if not dst then
|
||||
printError("Destination drive not found")
|
||||
failure = true
|
||||
end
|
||||
|
||||
if src and not src.isReady() then
|
||||
printError("Source drive is empty")
|
||||
failure = true
|
||||
end
|
||||
|
||||
if dst and not dst.isReady() then
|
||||
printError("Destination drive is empty")
|
||||
failure = true
|
||||
end
|
||||
|
||||
if failure then
|
||||
printError("Some errors occurred, exiting")
|
||||
return
|
||||
end
|
||||
|
||||
src.seek(-src.getSize())
|
||||
if seekToStart then
|
||||
dst.seek(-dst.getSize())
|
||||
end
|
||||
|
||||
local _, y = term.getCursorPos()
|
||||
while not src.isEnd() do
|
||||
dst.write(src.read(6000 * 10))
|
||||
local pos, sz = src.getPosition(), src.getSize()
|
||||
term.setCursorPos(1, y)
|
||||
term.clearLine()
|
||||
textProgress(pos / sz, colors.green, colors.gray, "%7.3f%% %8d / %8d", pos * 100 / sz, pos, sz)
|
||||
os.sleep(0.01)
|
||||
end
|
||||
|
Loading…
Reference in New Issue