Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local internet = component.internet
- local filesystem = require("filesystem")
- local shell = require("shell")
- local roms = {
- {name = "Pong", url = "https://github.com/brianhang/chip8-lua/blob/master/ROM/PONG"},
- {name = "Tetris", url = "https://github.com/brianhang/chip8-lua/blob/master/ROM/TETRIS"},
- {name = "Space Invaders", url = "https://github.com/brianhang/chip8-lua/blob/master/ROM/INVADERS"}
- }
- local function downloadRom(url, savePath)
- local handle, reason = internet.request(url)
- if not handle then
- return false, reason
- end
- local file, reason = io.open(savePath, "wb")
- if not file then
- return false, reason
- end
- for chunk in handle do
- file:write(chunk)
- end
- file:close()
- return true
- end
- local function showMenu()
- print("Select a ROM to download:")
- for i, rom in ipairs(roms) do
- print(string.format("%d. %s", i, rom.name))
- end
- print("Enter the number of the ROM you want to download:")
- local choice = tonumber(io.read())
- if choice and choice >= 1 and choice <= #roms then
- return roms[choice]
- else
- return nil, "Invalid choice"
- end
- end
- local function main()
- if not filesystem.exists("/home/ROMS") then
- filesystem.makeDirectory("/home/ROMS")
- end
- local rom, err = showMenu()
- if not rom then
- print("Error: " .. err)
- return
- end
- local savePath = "/home/ROMS/" .. rom.name .. ".ch8"
- print("Downloading " .. rom.name .. "...")
- local success, reason = downloadRom(rom.url, savePath)
- if success then
- print("Downloaded successfully and saved to " .. savePath)
- else
- print("Failed to download: " .. reason)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement