metroflip_scene_save_result.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "../metroflip_i.h"
  2. #include "../api/metroflip/metroflip_api.h"
  3. #include <stdio.h>
  4. enum PopupEvent {
  5. PopupEventExit,
  6. };
  7. static void metroflip_scene_save_result_popup_callback(void* context) {
  8. Metroflip* app = context;
  9. view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit);
  10. }
  11. void metroflip_scene_save_result_on_enter(void* context) {
  12. Metroflip* app = context;
  13. Popup* popup = app->popup;
  14. char path[280];
  15. snprintf(path, sizeof(path), "/ext/apps_data/metroflip/%s.metro", app->save_buf);
  16. FURI_LOG_I("path", "path: %s", path);
  17. bool success = nfc_device_save(app->nfc_device, path);
  18. Storage* storage = furi_record_open(RECORD_STORAGE);
  19. FlipperFormat* ff = flipper_format_file_alloc(storage);
  20. //flipper_format_buffered_file_open_existing(ff, path);
  21. flipper_format_write_empty_line(ff);
  22. if(flipper_format_file_open_existing(ff, path)) {
  23. if(flipper_format_insert_or_update_string_cstr(ff, "Card Type", app->card_type)) {
  24. flipper_format_file_close(ff);
  25. } else {
  26. FURI_LOG_I("ting", "cant write");
  27. }
  28. } else {
  29. FURI_LOG_I("ting", "not found");
  30. }
  31. flipper_format_free(ff);
  32. furi_record_close(RECORD_STORAGE);
  33. if(success) {
  34. popup_set_icon(popup, 36, 5, &I_DolphinDone_80x58);
  35. popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
  36. popup_enable_timeout(popup);
  37. } else {
  38. popup_set_icon(popup, 69, 15, &I_WarningDolphinFlip_45x42);
  39. popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
  40. popup_disable_timeout(popup);
  41. }
  42. popup_set_timeout(popup, 1500);
  43. popup_set_context(popup, app);
  44. popup_set_callback(popup, metroflip_scene_save_result_popup_callback);
  45. view_dispatcher_switch_to_view(app->view_dispatcher, MetroflipViewPopup);
  46. }
  47. bool metroflip_scene_save_result_on_event(void* context, SceneManagerEvent event) {
  48. Metroflip* app = context;
  49. bool consumed = false;
  50. if(event.type == SceneManagerEventTypeCustom) {
  51. consumed = true;
  52. switch(event.event) {
  53. case PopupEventExit:
  54. scene_manager_search_and_switch_to_previous_scene(
  55. app->scene_manager, MetroflipSceneStart);
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. return consumed;
  62. }
  63. void metroflip_scene_save_result_on_exit(void* context) {
  64. Metroflip* app = context;
  65. popup_reset(app->popup);
  66. }