Просмотр исходного кода

Merge pull request #27 from acegoal07/dev

Dev
acegoal07 1 год назад
Родитель
Сommit
a0bd65fb9c
2 измененных файлов с 11 добавлено и 17 удалено
  1. 9 15
      scenes/nfc_playlist_scene_file_rename.c
  2. 2 2
      scenes/nfc_playlist_scene_name_new_file.c

+ 9 - 15
scenes/nfc_playlist_scene_file_rename.c

@@ -7,19 +7,16 @@ 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* 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");
 
-   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));
+   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));
    }
    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);
 }
@@ -33,14 +30,11 @@ 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, 25, false);
 
    view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
 }

+ 2 - 2
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);
 }