nfc_playlist_scene_name_new_file.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "../nfc_playlist.h"
  2. void nfc_playlist_name_new_file_menu_callback(void* context) {
  3. NfcPlaylist* nfc_playlist = context;
  4. Storage* storage = furi_record_open(RECORD_STORAGE);
  5. FuriString* file_name = furi_string_alloc();
  6. furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
  7. FURI_LOG_I("Creating file: %s", furi_string_get_cstr(file_name));
  8. if (!storage_common_exists(storage, furi_string_get_cstr(file_name))) {
  9. File* file = storage_file_alloc(storage);
  10. storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW);
  11. storage_file_close(file);
  12. storage_file_free(file);
  13. }
  14. furi_string_move(nfc_playlist->settings.file_path, file_name);
  15. furi_string_free(file_name);
  16. furi_record_close(RECORD_STORAGE);
  17. scene_manager_previous_scene(nfc_playlist->scene_manager);
  18. }
  19. void nfc_playlist_name_new_file_scene_on_enter(void* context) {
  20. NfcPlaylist* nfc_playlist = context;
  21. nfc_playlist->text_input_output = (char*)malloc(50);
  22. text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
  23. text_input_set_minimum_length(nfc_playlist->text_input, 1);
  24. text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
  25. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_FileRename);
  26. }
  27. bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event) {
  28. UNUSED(context);
  29. UNUSED(event);
  30. return false;
  31. }
  32. void nfc_playlist_name_new_file_scene_on_exit(void* context) {
  33. NfcPlaylist* nfc_playlist = context;
  34. text_input_reset(nfc_playlist->text_input);
  35. free(nfc_playlist->text_input_output);
  36. }