blackhat_scene_scripts.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "../blackhat_app_i.h"
  2. static void blackhat_scene_script_list_enter_callback(
  3. void* context, uint32_t index
  4. )
  5. {
  6. furi_assert(context);
  7. BlackhatApp* app = context;
  8. app->selected_tx_string = "bh script run";
  9. app->selected_option_item_text = app->cmd[index + 1];
  10. app->text_input_req = false;
  11. app->selected_menu_index = index;
  12. FURI_LOG_I("tag/app name", "%s", app->selected_tx_string);
  13. scene_manager_set_scene_state(
  14. app->scene_manager, BlackhatSceneStart, app->selected_menu_index
  15. );
  16. scene_manager_next_scene(app->scene_manager, BlackhatAppViewConsoleOutput);
  17. }
  18. static void blackhat_scene_script_list_change_callback(VariableItem* item)
  19. {
  20. furi_assert(item); // REMOVE
  21. }
  22. void blackhat_scene_scripts_on_enter(void* context)
  23. {
  24. BlackhatApp* app = context;
  25. VariableItemList* var_item_list = app->script_item_list;
  26. size_t i = 0;
  27. int start = 0;
  28. memset(app->cmd, 0x00, sizeof(app->cmd));
  29. app->num_scripts = 0;
  30. while (app->script_text[i++]) {
  31. if (app->script_text[i] == '\n') {
  32. i++;
  33. app->cmd[app->num_scripts] = malloc(i - start);
  34. memcpy(
  35. app->cmd[app->num_scripts], &app->script_text[start], i - start
  36. );
  37. start = i;
  38. app->num_scripts++;
  39. }
  40. }
  41. variable_item_list_set_enter_callback(
  42. var_item_list, blackhat_scene_script_list_enter_callback, app
  43. );
  44. for (int i = 1; i < app->num_scripts; i++) {
  45. variable_item_list_add(
  46. var_item_list,
  47. app->cmd[i],
  48. 1,
  49. blackhat_scene_script_list_change_callback,
  50. app
  51. );
  52. }
  53. view_dispatcher_switch_to_view(
  54. app->view_dispatcher, BlackhatAppViewScriptItemList
  55. );
  56. }
  57. bool blackhat_scene_scripts_on_event(void* context, SceneManagerEvent event)
  58. {
  59. BlackhatApp* app = context;
  60. furi_assert(app); // REMOVE
  61. furi_assert(event); // REMOVE
  62. return false;
  63. }
  64. void blackhat_scene_scripts_on_exit(void* context)
  65. {
  66. BlackhatApp* app = context;
  67. // for(int i = 0 ; i < app->num_scripts ; i++) {
  68. // free(app->cmd[i]);
  69. // }
  70. variable_item_list_reset(app->script_item_list);
  71. scene_manager_search_and_switch_to_previous_scene(
  72. app->scene_manager, BlackhatSceneStart
  73. );
  74. }