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

New rename

- Fixes previous changes in dev where rename functionality was broken
- Makes it so the previous name is shown when renaming
acegoal07 1 год назад
Родитель
Сommit
8d0e6d3e23
2 измененных файлов с 13 добавлено и 7 удалено
  1. 1 1
      README.md
  2. 12 6
      scenes/nfc_playlist_scene_file_rename.c

+ 1 - 1
README.md

@@ -10,7 +10,7 @@ All the playlists should be placed in ext/apps_data/nfc_playlist and an example
 ```
 An example file can be found in the repository
 ## How to build
-This app was design, built and tested using the <a href="https://github.com/Flipper-XFW/Xtreme-Firmware">Xtreme firmware</a> so keep that in mind when building the FAP for yourself
+This app was design, built and tested using the <a href="https://github.com/Next-Flip/Momentum-Firmware">Momentum</a> so keep that in mind when building the FAP for yourself
 ## Supported Firmwares
 As i know these firmwares are supported and working if you know any more please let me know
 - <a href="https://github.com/Flipper-XFW/Xtreme-Firmware">Xtreme</a>

+ 12 - 6
scenes/nfc_playlist_scene_file_rename.c

@@ -3,15 +3,14 @@
 void nfc_playlist_file_rename_menu_callback(void* context) {
    NfcPlaylist* nfc_playlist = context;
    Storage* storage = furi_record_open(RECORD_STORAGE);
-   FuriString* tmp_old_file_path = furi_string_alloc();
-   FuriString* tmp_new_file_path = furi_string_alloc();
 
    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;
 
-   furi_string_printf(tmp_old_file_path, "%s", 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))) {
@@ -27,10 +26,17 @@ void nfc_playlist_file_rename_menu_callback(void* context) {
 
 void nfc_playlist_file_rename_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
-   nfc_playlist->text_input_output = (char*)malloc(50);
+
+   char const* tmp_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
+   char const* tmp_file_name = strchr(tmp_file_path, '/') != NULL ? &strrchr(tmp_file_path, '/')[1] : tmp_file_path;
+
+   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*)furi_string_get_cstr(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, true);
+   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);
 }