metroflip_scene_load.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, NULL);
  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_string_free(card_type);
  42. furi_record_close(RECORD_STORAGE);
  43. }
  44. bool metroflip_scene_load_on_event(void* context, SceneManagerEvent event) {
  45. Metroflip* app = context;
  46. UNUSED(event);
  47. bool consumed = false;
  48. // If they don't select any file in the brwoser and press back button,
  49. // the data is not loaded
  50. if(!app->data_loaded) {
  51. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, MetroflipSceneStart);
  52. }
  53. consumed = true;
  54. return consumed;
  55. }
  56. void metroflip_scene_load_on_exit(void* context) {
  57. Metroflip* app = context;
  58. UNUSED(app);
  59. }