metroflip_scene_load.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../metroflip_i.h"
  2. #include <dolphin/dolphin.h>
  3. #include <furi.h>
  4. #include <bit_lib.h>
  5. #include <lib/nfc/protocols/nfc_protocol.h>
  6. #include "../api/metroflip/metroflip_api.h"
  7. #define TAG "Metroflip:Scene:Load"
  8. void metroflip_scene_load_on_enter(void* context) {
  9. Metroflip* app = (Metroflip*)context;
  10. // We initialized this to be false every time we enter
  11. app->data_loaded = false;
  12. // The same string we will use to direct parse scene which plugin to call
  13. // Extracted from the file
  14. FuriString* card_type = furi_string_alloc();
  15. // All the app_data browser stuff. Don't worry about this
  16. DialogsFileBrowserOptions browser_options;
  17. Storage* storage = furi_record_open(RECORD_STORAGE);
  18. storage_simply_mkdir(storage, STORAGE_APP_DATA_PATH_PREFIX);
  19. dialog_file_browser_set_basic_options(&browser_options, METROFLIP_FILE_EXTENSION, &I_icon);
  20. browser_options.base_path = STORAGE_APP_DATA_PATH_PREFIX;
  21. FuriString* file_path = furi_string_alloc_set(browser_options.base_path);
  22. if(dialog_file_browser_show(app->dialogs, file_path, file_path, &browser_options)) {
  23. FlipperFormat* format = flipper_format_file_alloc(storage);
  24. do {
  25. if(!flipper_format_file_open_existing(format, furi_string_get_cstr(file_path))) break;
  26. if(!flipper_format_read_string(format, "Card Type", card_type)) break;
  27. if(furi_string_equal_str(card_type, "suica")) {
  28. }
  29. app->data_loaded = true;
  30. } while(0);
  31. flipper_format_free(format);
  32. }
  33. if(app->data_loaded) {
  34. // Direct to the parsing screen just like the auto scene does
  35. app->card_type = furi_string_get_cstr(card_type);
  36. scene_manager_next_scene(app->scene_manager, MetroflipSceneParse);
  37. } else {
  38. scene_manager_next_scene(app->scene_manager, MetroflipSceneStart);
  39. }
  40. furi_string_free(file_path);
  41. furi_record_close(RECORD_STORAGE);
  42. }
  43. bool metroflip_scene_load_on_event(void* context, SceneManagerEvent event) {
  44. Metroflip* app = context;
  45. UNUSED(event);
  46. bool consumed = false;
  47. // If they don't select any file in the brwoser and press back button,
  48. // the data is not loaded
  49. if(!app->data_loaded) {
  50. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, MetroflipSceneStart);
  51. }
  52. consumed = true;
  53. return consumed;
  54. }
  55. void metroflip_scene_load_on_exit(void* context) {
  56. Metroflip* app = context;
  57. UNUSED(app);
  58. }