From f387a6adde517d0f465b794dfe74cdbeeb2c4244 Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Tue, 21 May 2024 10:52:07 +0100 Subject: [PATCH 1/5] Just some tweaks --- scenes/nfc_playlist_scene_file_rename.c | 1 + scenes/nfc_playlist_scene_name_new_file.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scenes/nfc_playlist_scene_file_rename.c b/scenes/nfc_playlist_scene_file_rename.c index 47811a01091..8e2a89cbf2c 100644 --- a/scenes/nfc_playlist_scene_file_rename.c +++ b/scenes/nfc_playlist_scene_file_rename.c @@ -17,6 +17,7 @@ void nfc_playlist_file_rename_menu_callback(void* context) { storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(tmp_new_file_path)); nfc_playlist->settings.file_path = furi_string_alloc_set_str(furi_string_get_cstr(tmp_new_file_path)); } + furi_record_close(RECORD_STORAGE); furi_string_free(tmp_new_file_path); furi_string_free(tmp_old_file_path); diff --git a/scenes/nfc_playlist_scene_name_new_file.c b/scenes/nfc_playlist_scene_name_new_file.c index 60e0fb7b22b..e1e61140d86 100644 --- a/scenes/nfc_playlist_scene_name_new_file.c +++ b/scenes/nfc_playlist_scene_name_new_file.c @@ -23,10 +23,10 @@ void nfc_playlist_name_new_file_menu_callback(void* context) { void nfc_playlist_name_new_file_scene_on_enter(void* context) { NfcPlaylist* nfc_playlist = context; - nfc_playlist->text_input_output = (char*)malloc(50); + nfc_playlist->text_input_output = (char*)malloc(50*sizeof(char)); 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_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true); + text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50*sizeof(char), true); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); } From 198b9ced365dc6941f89857966ef369cbac7dfa8 Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Tue, 21 May 2024 23:41:43 +0100 Subject: [PATCH 2/5] Update nfc_playlist_scene_file_rename.c --- scenes/nfc_playlist_scene_file_rename.c | 29 +++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/scenes/nfc_playlist_scene_file_rename.c b/scenes/nfc_playlist_scene_file_rename.c index 8e2a89cbf2c..f90dfaf8d68 100644 --- a/scenes/nfc_playlist_scene_file_rename.c +++ b/scenes/nfc_playlist_scene_file_rename.c @@ -7,20 +7,19 @@ void nfc_playlist_file_rename_menu_callback(void* context) { char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path); char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path; - FuriString* tmp_old_file_path = furi_string_alloc_set_str(old_file_path); - furi_string_replace(tmp_old_file_path, old_file_name, ""); - - FuriString* tmp_new_file_path = furi_string_alloc(); - furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->text_input_output); - - if(!storage_file_exists(storage, furi_string_get_cstr(tmp_new_file_path))) { - storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(tmp_new_file_path)); - nfc_playlist->settings.file_path = furi_string_alloc_set_str(furi_string_get_cstr(tmp_new_file_path)); + FuriString* new_file_path = furi_string_alloc_set_str(old_file_path); + furi_string_replace(new_file_path, old_file_name, nfc_playlist->text_input_output); + furi_string_cat_str(new_file_path, ".txt"); + char const* new_file_path_cstr = furi_string_get_cstr(new_file_path); + + if(!storage_file_exists(storage, new_file_path_cstr)) { + storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr); + furi_string_free(nfc_playlist->settings.file_path); + nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_path_cstr); } - + furi_record_close(RECORD_STORAGE); - furi_string_free(tmp_new_file_path); - furi_string_free(tmp_old_file_path); + furi_string_free(new_file_path); scene_manager_previous_scene(nfc_playlist->scene_manager); } @@ -34,14 +33,12 @@ void nfc_playlist_file_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 = (char*)malloc(50 * sizeof(char)); - strcpy(nfc_playlist->text_input_output, furi_string_get_cstr(tmp_file_name_furi)); - + nfc_playlist->text_input_output = strdup(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"); text_input_set_minimum_length(nfc_playlist->text_input, 1); - text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, (50*sizeof(char)), false); + text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, (50 * sizeof(char)), false); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); } From 94443e763cb4c5b8a06426bca0caa67f70de8c0b Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Wed, 22 May 2024 00:13:06 +0100 Subject: [PATCH 3/5] Update nfc_playlist_scene_file_rename.c --- scenes/nfc_playlist_scene_file_rename.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scenes/nfc_playlist_scene_file_rename.c b/scenes/nfc_playlist_scene_file_rename.c index f90dfaf8d68..29522931a6d 100644 --- a/scenes/nfc_playlist_scene_file_rename.c +++ b/scenes/nfc_playlist_scene_file_rename.c @@ -12,12 +12,17 @@ void nfc_playlist_file_rename_menu_callback(void* context) { furi_string_cat_str(new_file_path, ".txt"); char const* new_file_path_cstr = furi_string_get_cstr(new_file_path); - if(!storage_file_exists(storage, new_file_path_cstr)) { - storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr); + if (storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr) == 0) { furi_string_free(nfc_playlist->settings.file_path); nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_path_cstr); } + // if (!storage_file_exists(storage, new_file_path_cstr)) { + // storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr); + // furi_string_free(nfc_playlist->settings.file_path); + // nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_path_cstr); + // } + furi_record_close(RECORD_STORAGE); furi_string_free(new_file_path); From 90eb26d9985babb3732c6d33c47e62467c0b97a4 Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Wed, 22 May 2024 01:49:50 +0100 Subject: [PATCH 4/5] Update nfc_playlist_scene_file_rename.c --- scenes/nfc_playlist_scene_file_rename.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/scenes/nfc_playlist_scene_file_rename.c b/scenes/nfc_playlist_scene_file_rename.c index 29522931a6d..cfb777d02bd 100644 --- a/scenes/nfc_playlist_scene_file_rename.c +++ b/scenes/nfc_playlist_scene_file_rename.c @@ -10,19 +10,11 @@ void nfc_playlist_file_rename_menu_callback(void* context) { FuriString* new_file_path = furi_string_alloc_set_str(old_file_path); furi_string_replace(new_file_path, old_file_name, nfc_playlist->text_input_output); furi_string_cat_str(new_file_path, ".txt"); - char const* new_file_path_cstr = furi_string_get_cstr(new_file_path); - if (storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr) == 0) { - furi_string_free(nfc_playlist->settings.file_path); - nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_path_cstr); + if(!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) { + storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(new_file_path)); + nfc_playlist->settings.file_path = furi_string_alloc_set_str(furi_string_get_cstr(new_file_path)); } - - // if (!storage_file_exists(storage, new_file_path_cstr)) { - // storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_path_cstr); - // furi_string_free(nfc_playlist->settings.file_path); - // nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_path_cstr); - // } - furi_record_close(RECORD_STORAGE); furi_string_free(new_file_path); @@ -40,10 +32,9 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) { nfc_playlist->text_input_output = strdup(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"); text_input_set_minimum_length(nfc_playlist->text_input, 1); - text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, (50 * sizeof(char)), false); + text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, false); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); } From 20898f13503e4c1f5c628083bb31c929cb12e519 Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Wed, 22 May 2024 02:02:32 +0100 Subject: [PATCH 5/5] Update nfc_playlist_scene_file_rename.c --- scenes/nfc_playlist_scene_file_rename.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scenes/nfc_playlist_scene_file_rename.c b/scenes/nfc_playlist_scene_file_rename.c index cfb777d02bd..8a3cd0d41ef 100644 --- a/scenes/nfc_playlist_scene_file_rename.c +++ b/scenes/nfc_playlist_scene_file_rename.c @@ -34,7 +34,7 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) { furi_string_free(tmp_file_name_furi); text_input_set_header_text(nfc_playlist->text_input, "Enter new file name"); text_input_set_minimum_length(nfc_playlist->text_input, 1); - text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, false); + text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 25, false); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); }