diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua index f9474eb15..fbcdeef65 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua @@ -1,17 +1,41 @@ local component = require("component") local shell = require("shell") +local fs = require("filesystem") local args, options = shell.parse(...) if #args < 1 and not options.l then - io.write("Usage: flash [-ql] [] [label]\n") + io.write("Usage: flash [-qlr] [] [label]\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 end +local eeprom = component.eeprom + 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 sure 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 end @@ -26,8 +50,6 @@ if not options.q then io.write("Beginning to flash EEPROM.\n") end -local eeprom = component.eeprom - if not options.q then io.write("Flashing EEPROM " .. eeprom.address .. ".\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 io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n") -end \ No newline at end of file +end