Skip to content

Commit a0bd65f

Browse files
authored
Merge pull request #27 from acegoal07/dev
Dev
2 parents 9f7dd64 + 20898f1 commit a0bd65f

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

scenes/nfc_playlist_scene_file_rename.c

+9-15
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ void nfc_playlist_file_rename_menu_callback(void* context) {
77
char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
88
char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path;
99

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, "");
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");
1213

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));
14+
if(!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) {
15+
storage_common_rename(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(new_file_path));
16+
nfc_playlist->settings.file_path = furi_string_alloc_set_str(furi_string_get_cstr(new_file_path));
1917
}
2018
furi_record_close(RECORD_STORAGE);
21-
furi_string_free(tmp_new_file_path);
22-
furi_string_free(tmp_old_file_path);
19+
furi_string_free(new_file_path);
2320

2421
scene_manager_previous_scene(nfc_playlist->scene_manager);
2522
}
@@ -33,14 +30,11 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) {
3330
FuriString* tmp_file_name_furi = furi_string_alloc_set_str(tmp_file_name);
3431
furi_string_replace(tmp_file_name_furi, ".txt", "");
3532

36-
nfc_playlist->text_input_output = (char*)malloc(50 * sizeof(char));
37-
strcpy(nfc_playlist->text_input_output, furi_string_get_cstr(tmp_file_name_furi));
38-
33+
nfc_playlist->text_input_output = strdup(furi_string_get_cstr(tmp_file_name_furi));
3934
furi_string_free(tmp_file_name_furi);
40-
4135
text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");
4236
text_input_set_minimum_length(nfc_playlist->text_input, 1);
43-
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);
37+
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 25, false);
4438

4539
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
4640
}

scenes/nfc_playlist_scene_name_new_file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ void nfc_playlist_name_new_file_menu_callback(void* context) {
2323

2424
void nfc_playlist_name_new_file_scene_on_enter(void* context) {
2525
NfcPlaylist* nfc_playlist = context;
26-
nfc_playlist->text_input_output = (char*)malloc(50);
26+
nfc_playlist->text_input_output = (char*)malloc(50*sizeof(char));
2727
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
2828
text_input_set_minimum_length(nfc_playlist->text_input, 1);
29-
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);
29+
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);
3030

3131
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
3232
}

0 commit comments

Comments
 (0)