brainfuck_scene_file_create.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "../brainfuck_i.h"
  2. void file_name_text_input_callback(void* context) {
  3. BFApp* app = context;
  4. view_dispatcher_send_custom_event(app->view_dispatcher, brainfuckCustomEventTextInputDone);
  5. }
  6. char tmpName[64] = {};
  7. rByte empty[1] = {0x00};
  8. void brainfuck_scene_file_create_on_enter(void* context) {
  9. BFApp* app = context;
  10. TextInput* text_input = app->text_input;
  11. text_input_set_header_text(text_input, "New script name");
  12. text_input_set_result_callback(
  13. text_input,
  14. file_name_text_input_callback,
  15. app,
  16. tmpName,
  17. 64,
  18. true);
  19. view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
  20. }
  21. bool brainfuck_scene_file_create_on_event(void* context, SceneManagerEvent event) {
  22. BFApp* app = context;
  23. UNUSED(app);
  24. bool consumed = false;
  25. if(event.type == SceneManagerEventTypeCustom) {
  26. if(event.event == brainfuckCustomEventTextInputDone) {
  27. furi_string_cat_printf(app->BF_file_path, "/ext/brainfuck/%s.b", tmpName);
  28. //remove old file
  29. Storage* storage = furi_record_open(RECORD_STORAGE);
  30. storage_simply_remove(storage, furi_string_get_cstr(app->BF_file_path));
  31. //save new file
  32. Stream* stream = buffered_file_stream_alloc(storage);
  33. buffered_file_stream_open(stream, furi_string_get_cstr(app->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
  34. stream_write(stream, empty, 1);
  35. buffered_file_stream_close(stream);
  36. //scene_manager_next_scene(app->scene_manager, brainfuckSceneFileSelect);
  37. scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
  38. }
  39. }
  40. return consumed;
  41. }
  42. void brainfuck_scene_file_create_on_exit(void* context) {
  43. UNUSED(context);
  44. }