Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("CBM")
- local args = {...}
- if #args ~= 2 then
- print("Usage: Convert-CBM <filepath-to-export> <new-filepath>")
- return
- end
- local filepath = args[1]
- local newpath = args[2]
- if not fs.exists(filepath) then
- print("Error: File not found")
- return
- end
- if fs.isDir(filepath) then
- print(filepath, " is a directory")
- return
- end
- if fs.exists(newpath) then
- print(newpath, " already exists")
- return
- end
- print("Exporting to CBM...")
- local lines = {}
- local file = fs.open(filepath, "r")
- while true do
- local line = file.readLine()
- if not line then break end
- table.insert(lines, line)
- end
- file.close()
- pixels = {}
- for _=1,#lines do table.insert(pixels, {}) end
- for i=1,#lines do
- pixels[i] = {}
- for hex in string.gmatch(lines[i], "[0-9a-f ]") do
- table.insert(pixels[i], tonumber(hex, 16) or -1)
- end
- end
- local height = #pixels
- local width = #pixels[1]
- if width == 0 or height == 0 then
- print("Corrupt file")
- return
- end
- for i=2,#pixels do
- if #pixels[i] ~= width then
- print("Corrupt file")
- return
- end
- end
- CBM.saveCBM(newpath, pixels, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement