mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Add ability to save current EEPROM to file in flash.lua
This commit is contained in:
parent
5d3879d0a4
commit
d9cfdfa5d7
@ -1,17 +1,41 @@
|
|||||||
local component = require("component")
|
local component = require("component")
|
||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
|
local fs = require("filesystem")
|
||||||
|
|
||||||
local args, options = shell.parse(...)
|
local args, options = shell.parse(...)
|
||||||
|
|
||||||
if #args < 1 and not options.l then
|
if #args < 1 and not options.l then
|
||||||
io.write("Usage: flash [-ql] [<bios.lua>] [label]\n")
|
io.write("Usage: flash [-qlr] [<bios.lua>] [label]\n")
|
||||||
io.write(" q: quiet mode, don't ask questions.\n")
|
io.write(" q: quiet mode, don't ask questions.\n")
|
||||||
io.write(" l: print current contents of installed EEPROM.")
|
io.write(" l: print current contents of installed EEPROM.\n")
|
||||||
|
io.write(" r: save the current contents of installed EEPROM to file.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local eeprom = component.eeprom
|
||||||
|
|
||||||
if options.l then
|
if options.l then
|
||||||
io.write(component.eeprom.get())
|
io.write(eeprom.get())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if options.r then
|
||||||
|
fileName = shell.resolve(args[1])
|
||||||
|
if not options.q then
|
||||||
|
if fs.exists(fileName) then
|
||||||
|
io.write("Are you want to overwrite " .. fileName .. "?\n")
|
||||||
|
io.write("Type `y` to confirm.\n")
|
||||||
|
repeat
|
||||||
|
local response = io.read()
|
||||||
|
until response and response:lower():sub(1, 1) == "y"
|
||||||
|
end
|
||||||
|
io.write("Reading EEPROM " .. eeprom.address .. ".\n" )
|
||||||
|
end
|
||||||
|
file = io.open(fileName, 'wb')
|
||||||
|
local bios = eeprom.get()
|
||||||
|
file:write(bios)
|
||||||
|
file:close()
|
||||||
|
if not options.q then io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n") end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,8 +50,6 @@ if not options.q then
|
|||||||
io.write("Beginning to flash EEPROM.\n")
|
io.write("Beginning to flash EEPROM.\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
local eeprom = component.eeprom
|
|
||||||
|
|
||||||
if not options.q then
|
if not options.q then
|
||||||
io.write("Flashing EEPROM " .. eeprom.address .. ".\n")
|
io.write("Flashing EEPROM " .. eeprom.address .. ".\n")
|
||||||
io.write("Please do NOT power down or restart your computer during this operation!\n")
|
io.write("Please do NOT power down or restart your computer during this operation!\n")
|
||||||
@ -52,4 +74,4 @@ end
|
|||||||
|
|
||||||
if not options.q then
|
if not options.q then
|
||||||
io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n")
|
io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user