@@ -7,20 +7,19 @@ void nfc_playlist_file_rename_menu_callback(void* context) {
7
7
char const * old_file_path = (char * )furi_string_get_cstr (nfc_playlist -> settings .file_path );
8
8
char const * old_file_name = strchr (old_file_path , '/' ) != NULL ? & strrchr (old_file_path , '/' )[1 ] : old_file_path ;
9
9
10
- FuriString * tmp_old_file_path = furi_string_alloc_set_str (old_file_path );
11
- furi_string_replace (tmp_old_file_path , old_file_name , "" );
12
-
13
- FuriString * tmp_new_file_path = furi_string_alloc ( );
14
- furi_string_printf ( tmp_new_file_path , "%s%s.txt" , furi_string_get_cstr ( tmp_old_file_path ), nfc_playlist -> text_input_output );
15
-
16
- if (! storage_file_exists ( storage , furi_string_get_cstr (tmp_new_file_path ))) {
17
- storage_common_rename_safe ( storage , furi_string_get_cstr ( nfc_playlist -> settings .file_path ), furi_string_get_cstr ( tmp_new_file_path ) );
18
- nfc_playlist -> settings .file_path = furi_string_alloc_set_str (furi_string_get_cstr ( tmp_new_file_path ) );
10
+ FuriString * new_file_path = furi_string_alloc_set_str (old_file_path );
11
+ furi_string_replace (new_file_path , old_file_name , nfc_playlist -> text_input_output );
12
+ furi_string_cat_str ( new_file_path , ".txt" );
13
+ char const * new_file_path_cstr = furi_string_get_cstr ( new_file_path );
14
+
15
+ if (! storage_file_exists ( storage , new_file_path_cstr )) {
16
+ storage_common_rename ( storage , furi_string_get_cstr (nfc_playlist -> settings . file_path ), new_file_path_cstr );
17
+ furi_string_free ( nfc_playlist -> settings .file_path );
18
+ nfc_playlist -> settings .file_path = furi_string_alloc_set_str (new_file_path_cstr );
19
19
}
20
-
20
+
21
21
furi_record_close (RECORD_STORAGE );
22
- furi_string_free (tmp_new_file_path );
23
- furi_string_free (tmp_old_file_path );
22
+ furi_string_free (new_file_path );
24
23
25
24
scene_manager_previous_scene (nfc_playlist -> scene_manager );
26
25
}
@@ -34,14 +33,12 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) {
34
33
FuriString * tmp_file_name_furi = furi_string_alloc_set_str (tmp_file_name );
35
34
furi_string_replace (tmp_file_name_furi , ".txt" , "" );
36
35
37
- nfc_playlist -> text_input_output = (char * )malloc (50 * sizeof (char ));
38
- strcpy (nfc_playlist -> text_input_output , furi_string_get_cstr (tmp_file_name_furi ));
39
-
36
+ nfc_playlist -> text_input_output = strdup (furi_string_get_cstr (tmp_file_name_furi ));
40
37
furi_string_free (tmp_file_name_furi );
41
38
42
39
text_input_set_header_text (nfc_playlist -> text_input , "Enter new file name" );
43
40
text_input_set_minimum_length (nfc_playlist -> text_input , 1 );
44
- 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);
41
+ 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);
45
42
46
43
view_dispatcher_switch_to_view (nfc_playlist -> view_dispatcher , NfcPlaylistView_TextInput );
47
44
}
0 commit comments