brainfuck_scene_file_create.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. byte 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, file_name_text_input_callback, app, tmpName, 64, true);
  14. view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
  15. }
  16. bool brainfuck_scene_file_create_on_event(void* context, SceneManagerEvent event) {
  17. BFApp* app = context;
  18. UNUSED(app);
  19. bool consumed = false;
  20. if(event.type == SceneManagerEventTypeCustom) {
  21. if(event.event == brainfuckCustomEventTextInputDone) {
  22. furi_string_cat_printf(app->BF_file_path, "/ext/brainfuck/%s.b", tmpName);
  23. //remove old file
  24. Storage* storage = furi_record_open(RECORD_STORAGE);
  25. storage_simply_remove(storage, furi_string_get_cstr(app->BF_file_path));
  26. //save new file
  27. Stream* stream = buffered_file_stream_alloc(storage);
  28. buffered_file_stream_open(
  29. stream, furi_string_get_cstr(app->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
  30. stream_write(stream, (const uint8_t*)empty, 1);
  31. buffered_file_stream_close(stream);
  32. //scene_manager_next_scene(app->scene_manager, brainfuckSceneFileSelect);
  33. scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
  34. }
  35. }
  36. return consumed;
  37. }
  38. void brainfuck_scene_file_create_on_exit(void* context) {
  39. UNUSED(context);
  40. }