fuzzer_scene_save_name.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "../fuzzer_i.h"
  2. #include <toolbox/name_generator.h>
  3. #include <toolbox/path.h>
  4. static void fuzzer_scene_save_name_text_input_callback(void* context) {
  5. PacsFuzzerApp* app = context;
  6. view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventTextEditResult);
  7. }
  8. void fuzzer_scene_save_name_on_enter(void* context) {
  9. PacsFuzzerApp* app = context;
  10. TextInput* text_input = app->text_input;
  11. name_generator_make_auto(app->key_name, KEY_NAME_SIZE, app->fuzzer_const->file_prefix);
  12. text_input_set_header_text(text_input, "Name the key");
  13. text_input_set_result_callback(
  14. text_input,
  15. fuzzer_scene_save_name_text_input_callback,
  16. app,
  17. app->key_name,
  18. KEY_NAME_SIZE,
  19. true);
  20. ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
  21. app->fuzzer_const->path_key_folder, app->fuzzer_const->key_extension, app->key_name);
  22. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  23. view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDTextInput);
  24. }
  25. bool fuzzer_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  26. PacsFuzzerApp* app = context;
  27. bool consumed = false;
  28. if(event.type == SceneManagerEventTypeCustom) {
  29. if(event.event == FuzzerCustomEventTextEditResult) {
  30. consumed = true;
  31. furi_string_printf(
  32. app->file_path,
  33. "%s/%s%s",
  34. app->fuzzer_const->path_key_folder,
  35. app->key_name,
  36. app->fuzzer_const->key_extension);
  37. if(fuzzer_worker_save_key(app->worker, furi_string_get_cstr(app->file_path))) {
  38. scene_manager_next_scene(app->scene_manager, FuzzerSceneSaveSuccess);
  39. } else {
  40. scene_manager_previous_scene(app->scene_manager);
  41. }
  42. }
  43. }
  44. return consumed;
  45. }
  46. void fuzzer_scene_save_name_on_exit(void* context) {
  47. PacsFuzzerApp* app = context;
  48. TextInput* text_input = app->text_input;
  49. void* validator_context = text_input_get_validator_callback_context(text_input);
  50. text_input_set_validator(text_input, NULL, NULL);
  51. validator_is_file_free((ValidatorIsFile*)validator_context);
  52. text_input_reset(text_input);
  53. }