Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function main()
- local ci = component.invoke
- local computer = computer or require("computer")
- local bi = function(a, m, ...)
- local r = table.pack(pcall(ci, a, m, ...))
- if not r[1] then return nil, r[2] else return table.unpack(r, 2, r.n) end
- end
- local e = component.list("eeprom")()
- computer.getBootAddress = function() return bi(e, "getData") end
- computer.setBootAddress = function(a) return bi(e, "setData", a) end
- do
- local s, g = component.list("screen")(), component.list("gpu")()
- if g and s then bi(g, "bind", s) end
- end
- local function tryLoad(a)
- local h, r = bi(a, "open", "/init.lua")
- if not h then return nil, "Failed to open /init.lua: " .. tostring(r) end
- local b = ""
- repeat
- local d, r = bi(a, "read", h, math.maxinteger or math.huge)
- if not d and r then
- bi(a, "close", h)
- return nil, "Failed to read /init.lua: " .. tostring(r)
- end
- b = b .. (d or "")
- until not d
- bi(a, "close", h)
- local i, l = load(b, "=init")
- if not i then return nil, "Failed to load /init.lua: " .. tostring(l) end
- return i
- end
- local function flashEEPROM(address)
- local h, r = bi(address, "open", "/DOGGY.ROM")
- if not h then return false, "Failed to open DOGGY.ROM: " .. tostring(r) end
- local totalSize = bi(address, "size", "/DOGGY.ROM")
- local pageSize = 64 -- Example EEPROM page size
- local chunkSize = math.min(totalSize, pageSize * 2) -- Choose a chunk size that is a multiple of page size, e.g., 128 bytes
- local data, chunk = "", ""
- local progressWidth = 20 -- Width of the progress bar
- repeat
- chunk = bi(address, "read", h, chunkSize)
- if chunk then
- bi(e, "set", data .. chunk) -- Write chunk to EEPROM
- data = data .. chunk
- local progress = #data / totalSize
- local progressBar = string.rep("=", math.floor(progress * progressWidth)) .. string.rep(" ", progressWidth - math.floor(progress * progressWidth))
- bi(component.list("gpu")(), "set", 1, 1, "Flashing: [" .. progressBar .. "] " .. math.floor(progress * 100) .. "%")
- end
- computer.pullSignal(6) -- Wait for 6 seconds
- until not chunk
- bi(address, "close", h)
- return true
- end
- local l = {}
- for a in component.list("filesystem") do
- local b = bi(a, "getLabel") or "Unnamed Drive"
- if b ~= "tmpfs" then
- table.insert(l, { address = a, label = b })
- end
- end
- -- Check for DOGGY.ROM and flash it to EEPROM if found
- for _, drive in ipairs(l) do
- local hasDoggyRom, err = bi(drive.address, "exists", "/DOGGY.ROM")
- if hasDoggyRom then
- local success, flashError = flashEEPROM(drive.address)
- if success then
- computer.beep(800, 0.2)
- computer.beep(800, 0.2)
- computer.beep(800, 0.2)
- bi(component.list("gpu")(), "set", 1, 1, "Flash complete!")
- computer.beep(800, 1) -- Beep once to indicate flash completion
- else
- bi(component.list("gpu")(), "set", 1, 1, "Flash failed: " .. flashError)
- computer.beep(800, 0.1)
- computer.beep(800, 0.1)
- computer.beep(800, 0.1)
- computer.beep(800, 1) -- Beep to indicate failure
- computer.shutdown(true) -- Halt the system
- end
- break
- end
- end
- local function displayError(errorMessage)
- -- Implementation remains the same
- end
- local function displayMenu(sI)
- -- Implementation remains the same
- end
- local sI = math.ceil(#l / 2)
- displayMenu(sI)
- while true do
- local e = { computer.pullSignal() }
- if e[1] == "key_down" then
- -- Implementation remains the same
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement