blackhat_scene_scripts.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. UNUSED(item);
  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. UNUSED(context);
  60. UNUSED(event);
  61. return false;
  62. }
  63. void blackhat_scene_scripts_on_exit(void* context)
  64. {
  65. BlackhatApp* app = context;
  66. // for(int i = 0 ; i < app->num_scripts ; i++) {
  67. // free(app->cmd[i]);
  68. // }
  69. variable_item_list_reset(app->script_item_list);
  70. scene_manager_search_and_switch_to_previous_scene(
  71. app->scene_manager, BlackhatSceneStart
  72. );
  73. }