removable_app.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. laptop.register_app("removable", {
  2. app_name = "Removable Storage",
  3. app_icon = "laptop_removable.png",
  4. app_info = "Interface with Removable Media",
  5. formspec_func = function(app, mtos)
  6. local formspec =
  7. "list[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main;0,0.3;1,1;]" ..
  8. "list[current_player;main;0,4.85;8,1;]" ..
  9. "list[current_player;main;0,6.08;8,3;8]" ..
  10. "listring[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main]" ..
  11. "listring[current_player;main]"..
  12. "background[0,0.3;8,1;".. mtos.theme.contrast_background .. ']'
  13. mtos.bdev.removable_disk = nil -- force reading
  14. local idata = mtos.bdev:get_removable_disk()
  15. if idata.stack then
  16. -- change label
  17. formspec = formspec .. "field[2,0.65;4,1;label;;"..idata.label.."]"..
  18. mtos.theme:get_button('5.7,0.5;1.5,0.7', 'minor', 'set_label', 'Rename', 'Rename the '..idata.def.description)..
  19. mtos.theme:get_label('0,1.5', idata.def.description)..
  20. mtos.theme:get_label('0,2', "Format: "..idata.os_format)..
  21. -- buttons
  22. mtos.theme:get_button('0,3;1.5,0.7', 'minor', 'format_wipe', 'wipe', 'Wipe all data from disk')..
  23. mtos.theme:get_button('0,4;1.5,0.7', 'minor', 'format_data', 'data', 'Format disk to store data')
  24. if idata.def.groups.laptop_removable_usb then
  25. formspec = formspec .. mtos.theme:get_button('2,3;1.5,0.7', 'minor', 'format_backup', 'backup', 'Store backup to disk')
  26. end
  27. if idata.os_format == "backup" then
  28. formspec = formspec .. mtos.theme:get_button('2,4;1.5,0.7', 'minor', 'restore', 'restore', 'Restore from backup disk')
  29. end
  30. -- format CS-BOS
  31. if idata.def.groups.laptop_removable_floppy then
  32. formspec = formspec .. mtos.theme:get_button('4,3;1.5,0.7', 'minor', 'format_csbos', 'CS-BOS', 'Format disk to boot CS-BOS ')
  33. end
  34. end
  35. return formspec
  36. end,
  37. receive_fields_func = function(app, mtos, sender, fields)
  38. local idata = mtos.bdev:get_removable_disk()
  39. if idata.stack then
  40. if fields.set_label then
  41. idata.label = fields.label
  42. elseif fields.format_wipe then
  43. idata:format_disk()
  44. elseif fields.format_data then
  45. idata:format_disk("data", "Data "..idata.def.description)
  46. elseif fields.format_backup then
  47. idata:format_disk("backup", "Backup of "..mtos.hwdef.description.." from "..os.date('%x'))
  48. idata.meta:set_string("backup_data", mtos.meta:get_string('laptop_appdata'))
  49. elseif fields.format_csbos then
  50. idata:format_disk("boot", "CS-BOS Boot Disk")
  51. elseif fields.restore then
  52. mtos.meta:set_string('laptop_appdata', idata.meta:get_string("backup_data"))
  53. mtos.bdev = laptop.get_bdev_handler(mtos)
  54. mtos:power_on() --reboot
  55. end
  56. end
  57. laptop.mtos_cache:sync_and_free(mtos)
  58. end,
  59. })