3
3
int32_t nfc_playlist_playlist_rename_thread_task (void * context ) {
4
4
NfcPlaylist * nfc_playlist = context ;
5
5
6
- char const * old_file_path = furi_string_get_cstr (nfc_playlist -> settings .playlist_path );
7
- char const * old_file_name = strchr (old_file_path , '/' ) != NULL ? & strrchr (old_file_path , '/' )[1 ] : old_file_path ;
8
- FuriString * new_file_path = furi_string_alloc_set_str (old_file_path );
9
- furi_string_replace (new_file_path , old_file_name , nfc_playlist -> text_input_output );
6
+ FuriString * old_file_path = furi_string_alloc ();
7
+ path_extract_dirname (furi_string_get_cstr (nfc_playlist -> settings .playlist_path ), old_file_path );
8
+ FuriString * new_file_path = furi_string_alloc_set (old_file_path );
9
+ path_concat (furi_string_get_cstr (old_file_path ), nfc_playlist -> text_input_output , new_file_path );
10
+ furi_string_free (old_file_path );
10
11
furi_string_cat_str (new_file_path , ".txt" );
11
-
12
+
12
13
Storage * storage = furi_record_open (RECORD_STORAGE );
13
14
14
15
if (!storage_file_exists (storage , furi_string_get_cstr (new_file_path ))) {
15
- if (storage_common_rename (storage , old_file_path , furi_string_get_cstr (new_file_path )) == 0 ) {
16
- furi_string_move (nfc_playlist -> settings .playlist_path , new_file_path );
16
+ if (storage_common_rename (storage , furi_string_get_cstr ( nfc_playlist -> settings . playlist_path ) , furi_string_get_cstr (new_file_path )) == FSE_OK ) {
17
+ furi_string_swap (nfc_playlist -> settings .playlist_path , new_file_path );
17
18
}
18
19
}
19
20
21
+ furi_string_free (new_file_path );
22
+
20
23
furi_record_close (RECORD_STORAGE );
21
24
22
25
return 0 ;
@@ -42,14 +45,12 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) {
42
45
void nfc_playlist_playlist_rename_scene_on_enter (void * context ) {
43
46
NfcPlaylist * nfc_playlist = context ;
44
47
45
- char const * tmp_file_path = furi_string_get_cstr (nfc_playlist -> settings .playlist_path );
46
- char const * tmp_file_name = strchr (tmp_file_path , '/' ) != NULL ? & strrchr (tmp_file_path , '/' )[1 ] : tmp_file_path ;
47
- FuriString * tmp_file_name_furi = furi_string_alloc_set_str (tmp_file_name );
48
- furi_string_replace (tmp_file_name_furi , ".txt" , "" );
48
+ FuriString * tmp_file_name = furi_string_alloc ();
49
+ path_extract_filename_no_ext (furi_string_get_cstr (nfc_playlist -> settings .playlist_path ), tmp_file_name );
49
50
50
51
nfc_playlist -> text_input_output = malloc (MAX_PLAYLIST_NAME_LEN + 1 );
51
- strcpy (nfc_playlist -> text_input_output , furi_string_get_cstr (tmp_file_name_furi ));
52
- furi_string_free (tmp_file_name_furi );
52
+ strcpy (nfc_playlist -> text_input_output , furi_string_get_cstr (tmp_file_name ));
53
+ furi_string_free (tmp_file_name );
53
54
54
55
text_input_set_header_text (nfc_playlist -> text_input , "Enter new file name" );
55
56
text_input_set_minimum_length (nfc_playlist -> text_input , 1 );
0 commit comments