diff --git a/README.md b/README.md index 5c38a3e09a7..f29f77ccd45 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,8 @@ As i know these firmwares are supported and working if you know any more please - Add NFC Item (Adds the selected nfc item to the currently selected playlist) - Remove NFC Item (Opens a menu allowing you to select a line to remove from the playlist) - View playlist content (Allows you to view the contents of the playlist) -## Development plans/ideas: -Things i would like to add: -- Ability to remove cards from the playlist - -These features are not guaranteed to be added but are being looked at as features to add +## Known issues +### Renaming/creating playlist +I know of an issue with these functions that can cause them to lock the viewport if you put in a name that is very long im looking into fixing this and finding a solution Any feedback is welcome and would be very much appreciated diff --git a/nfc_playlist.h b/nfc_playlist.h index 4f928432396..c6fcfedbae7 100644 --- a/nfc_playlist.h +++ b/nfc_playlist.h @@ -28,6 +28,10 @@ #include "scenes/nfc_playlist_scene.h" +#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/" +#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist" +#define PLAYLIST_NAME_LEN 100 + typedef enum { NfcPlaylistView_Submenu, NfcPlaylistView_Popup, @@ -72,10 +76,6 @@ static const int default_emulate_delay = 0; static const bool default_emulate_led_indicator = true; static const bool default_skip_error = false; -#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/" -#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist" -#define PLAYLIST_NAME_LEN 100 - typedef enum NfcPlaylistLedState { NfcPlaylistLedState_Normal, NfcPlaylistLedState_Error diff --git a/scenes/nfc_playlist_scene_name_new_playlist.c b/scenes/nfc_playlist_scene_name_new_playlist.c index f1652ac1de1..f0f1da2b50e 100644 --- a/scenes/nfc_playlist_scene_name_new_playlist.c +++ b/scenes/nfc_playlist_scene_name_new_playlist.c @@ -2,29 +2,30 @@ void nfc_playlist_name_new_playlist_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; - Storage* storage = furi_record_open(RECORD_STORAGE); - FuriString* file_name = furi_string_alloc(); - furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output); + FuriString* file_name = furi_string_alloc_printf("/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output); + char const* file_name_cstr = furi_string_get_cstr(file_name); + Storage* storage = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(storage); - if (storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW)) { - storage_file_close(file); - furi_string_swap(nfc_playlist->settings.playlist_path, file_name); + if (!storage_file_exists(storage, file_name_cstr)) { + if (storage_file_open(file, file_name_cstr, FSAM_READ_WRITE, FSOM_CREATE_NEW)) { + storage_file_close(file); + furi_string_swap(nfc_playlist->settings.playlist_path, file_name); + nfc_playlist->settings.playlist_length = 0; + } } - - nfc_playlist->settings.playlist_length = 0; - storage_file_free(file); - furi_string_free(file_name); furi_record_close(RECORD_STORAGE); + + furi_string_free(file_name); scene_manager_previous_scene(nfc_playlist->scene_manager); } void nfc_playlist_name_new_playlist_scene_on_enter(void* context) { NfcPlaylist* nfc_playlist = context; - nfc_playlist->text_input_output = (char*)malloc(PLAYLIST_NAME_LEN); + nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN); text_input_set_header_text(nfc_playlist->text_input, "Enter file name"); text_input_set_minimum_length(nfc_playlist->text_input, 1); text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_playlist_menu_callback, nfc_playlist, nfc_playlist->text_input_output, PLAYLIST_NAME_LEN, true); diff --git a/scenes/nfc_playlist_scene_playlist_rename.c b/scenes/nfc_playlist_scene_playlist_rename.c index f6a0dfcf810..1b04d5a1b2b 100644 --- a/scenes/nfc_playlist_scene_playlist_rename.c +++ b/scenes/nfc_playlist_scene_playlist_rename.c @@ -2,7 +2,6 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; - Storage* storage = furi_record_open(RECORD_STORAGE); char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.playlist_path); char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path; @@ -11,12 +10,14 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) { furi_string_replace(new_file_path, old_file_name, nfc_playlist->text_input_output); furi_string_cat_str(new_file_path, ".txt"); - if (storage_common_rename_safe(storage, old_file_path, furi_string_get_cstr(new_file_path)) == 0) { + Storage* storage = furi_record_open(RECORD_STORAGE); + if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) { + storage_common_rename(storage, old_file_path, furi_string_get_cstr(new_file_path)); furi_string_swap(nfc_playlist->settings.playlist_path, new_file_path); } + furi_record_close(RECORD_STORAGE); furi_string_free(new_file_path); - furi_record_close(RECORD_STORAGE); scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu); } @@ -30,7 +31,8 @@ void nfc_playlist_playlist_rename_scene_on_enter(void* context) { FuriString* tmp_file_name_furi = furi_string_alloc_set_str(tmp_file_name); furi_string_replace(tmp_file_name_furi, ".txt", ""); - nfc_playlist->text_input_output = strdup(furi_string_get_cstr(tmp_file_name_furi)); + nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN); + strcpy(nfc_playlist->text_input_output, furi_string_get_cstr(tmp_file_name_furi)); furi_string_free(tmp_file_name_furi); text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");