Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arguments = { ... }
- if #arguments == 0 then
- print("Usage: writeCode <path to code> [card label]")
- error()
- end
- if not fs.exists(arguments[1]) then
- print("Error: file not found")
- error()
- end
- if fs.isDir(arguments[1]) then
- print("Error: directory given")
- error()
- end
- code = {}
- file = fs.open(arguments[1], "rb")
- while true do
- local byte = file.read()
- if not byte then break end
- table.insert(code, string.char(byte))
- end
- code = table.concat(code)
- if code:len() > 100 then
- print("Error: code length exceeds 100 bytes")
- error()
- end
- function constructLabel()
- label = ""
- for n = 2, #arguments do
- label = label .. arguments[n]
- if n < #arguments then label = label .. " " end
- end
- return label
- end
- cardLabel = constructLabel()
- if cardLabel == "" then cardLabel = "No Label Given" end
- local side = nil;
- for _,side1 in ipairs(rs.getSides()) do
- if peripheral.getType(side1)=='mag card reader' then
- side = side1
- end
- end
- if not side then
- print("Error: No mag-card writer found")
- error()
- end
- peripheral.call(side, "beginWrite", code, cardLabel)
- while true do
- event = os.pullEvent("mag_write_done")
- if event == "mag_write_done" then
- print("Successfully wrote code to magCard")
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement