| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "../brainfuck_i.h"
- void file_name_text_input_callback(void* context) {
- BFApp* app = context;
- view_dispatcher_send_custom_event(app->view_dispatcher, brainfuckCustomEventTextInputDone);
- }
- char tmpName[64] = {};
- rByte empty[1] = {0x00};
- void brainfuck_scene_file_create_on_enter(void* context) {
- BFApp* app = context;
- TextInput* text_input = app->text_input;
- text_input_set_header_text(text_input, "New script name");
- text_input_set_result_callback(
- text_input,
- file_name_text_input_callback,
- app,
- tmpName,
- 64,
- true);
- view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
- }
- bool brainfuck_scene_file_create_on_event(void* context, SceneManagerEvent event) {
- BFApp* app = context;
- UNUSED(app);
-
- bool consumed = false;
- if(event.type == SceneManagerEventTypeCustom) {
- if(event.event == brainfuckCustomEventTextInputDone) {
- furi_string_cat_printf(app->BF_file_path, "/ext/brainfuck/%s.b", tmpName);
- //remove old file
- Storage* storage = furi_record_open(RECORD_STORAGE);
- storage_simply_remove(storage, furi_string_get_cstr(app->BF_file_path));
- //save new file
- Stream* stream = buffered_file_stream_alloc(storage);
- buffered_file_stream_open(stream, furi_string_get_cstr(app->BF_file_path), FSAM_WRITE, FSOM_CREATE_ALWAYS);
- stream_write(stream, empty, 1);
- buffered_file_stream_close(stream);
- //scene_manager_next_scene(app->scene_manager, brainfuckSceneFileSelect);
- scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
- }
- }
- return consumed;
- }
- void brainfuck_scene_file_create_on_exit(void* context) {
- UNUSED(context);
- }
|