فهرست منبع

Quality of life

- Improves how the renaming process is done making it more accurate and less likely to go wrong
- Improves confirm delete page removing the .txt at the end of the name
- Makes it so the whole app runs smoother
acegoal07 1 سال پیش
والد
کامیت
93cb03f051
11فایلهای تغییر یافته به همراه170 افزوده شده و 179 حذف شده
  1. 0 1
      nfc_playlist.c
  2. 5 3
      scences/confirm_delete.c
  3. 70 69
      scences/emulation.c
  4. 0 6
      scences/emulation.h
  5. 18 20
      scences/file_edit.c
  6. 6 1
      scences/file_edit.h
  7. 12 13
      scences/file_rename.c
  8. 1 30
      scences/main_menu.c
  9. 15 1
      scences/main_menu.h
  10. 35 34
      scences/settings.c
  11. 8 1
      scences/settings.h

+ 0 - 1
nfc_playlist.c

@@ -117,7 +117,6 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
 
 
    furi_string_free(nfc_playlist->settings.base_file_path);
    furi_string_free(nfc_playlist->settings.base_file_path);
    furi_string_free(nfc_playlist->settings.file_path);
    furi_string_free(nfc_playlist->settings.file_path);
-   free(nfc_playlist->playlist_name);
    free(nfc_playlist);
    free(nfc_playlist);
 }
 }
 
 

+ 5 - 3
scences/confirm_delete.c

@@ -14,6 +14,7 @@ void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
    FuriString* temp_str = furi_string_alloc();
    FuriString* temp_str = furi_string_alloc();
    char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
    char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path);
    furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
    furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
+   furi_string_replace(temp_str, ".txt", "");
 
 
    widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
    widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
    widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
    widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
@@ -27,16 +28,17 @@ void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
 bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) {
 bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
    bool consumed = false;
    bool consumed = false;
-   Storage* storage = furi_record_open(RECORD_STORAGE);
    if(event.type == SceneManagerEventTypeCustom) {
    if(event.type == SceneManagerEventTypeCustom) {
       switch(event.event) {
       switch(event.event) {
-         case GuiButtonTypeRight: {
+         case GuiButtonTypeRight:
+            Storage* storage = furi_record_open(RECORD_STORAGE);
             storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
             storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
             nfc_playlist->settings.file_selected = false;
             nfc_playlist->settings.file_selected = false;
             nfc_playlist->settings.file_selected_check = false;
             nfc_playlist->settings.file_selected_check = false;
             nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
             nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
+            furi_record_close(RECORD_STORAGE);
+            consumed = true;
             break;
             break;
-         }
          default:
          default:
             break;
             break;
       }
       }

+ 70 - 69
scences/emulation.c

@@ -3,61 +3,14 @@
 
 
 NfcPlaylistEmulationState EmulationState = NfcPlaylistEmulationState_Stopped;
 NfcPlaylistEmulationState EmulationState = NfcPlaylistEmulationState_Stopped;
 
 
-void nfc_playlist_emulation_scene_on_enter(void* context) {
-   NfcPlaylist* nfc_playlist = context;
-   nfc_playlist_emulation_setup(nfc_playlist);
-   nfc_playlist_emulation_start(nfc_playlist);
-}
-
-bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event) {
-   UNUSED(context);
-   if (event.event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
-      EmulationState = NfcPlaylistEmulationState_Canceled;
-      return true;
-   }
-   return false;
-}
-
-void nfc_playlist_emulation_scene_on_exit(void* context) {
-   NfcPlaylist* nfc_playlist = context;
-   EmulationState = NfcPlaylistEmulationState_Stopped;
-   nfc_playlist_emulation_stop(nfc_playlist);
-   nfc_playlist_emulation_free(nfc_playlist);
-   popup_reset(nfc_playlist->popup);
-}
-
-void nfc_playlist_emulation_setup(void* context) {
-   NfcPlaylist* nfc_playlist = context;
-   nfc_playlist->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 8192, nfc_playlist_emulation_task, nfc_playlist);
-   nfc_playlist->nfc_playlist_worker = nfc_playlist_worker_alloc();
-}
-
-void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist) {
-   furi_assert(nfc_playlist);
-   furi_thread_free(nfc_playlist->thread);
-   nfc_playlist_worker_free(nfc_playlist->nfc_playlist_worker);
-   nfc_playlist->thread = NULL;
-   nfc_playlist->nfc_playlist_worker = NULL;
-}
-
-void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist) {
-   furi_assert(nfc_playlist);
-   furi_thread_start(nfc_playlist->thread);
-}
-
-void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist) {
-   furi_assert(nfc_playlist);
-   furi_thread_join(nfc_playlist->thread);
-}
-
 int32_t nfc_playlist_emulation_task(void* context) {
 int32_t nfc_playlist_emulation_task(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
 
 
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Stream* stream = file_stream_alloc(storage);
    Stream* stream = file_stream_alloc(storage);
    FuriString* line = furi_string_alloc();
    FuriString* line = furi_string_alloc();
-   FuriString* temp_header_str = furi_string_alloc();
-   FuriString* temp_counter_str = furi_string_alloc();
+   FuriString* tmp_header_str = furi_string_alloc();
+   FuriString* tmp_counter_str = furi_string_alloc();
 
 
    popup_reset(nfc_playlist->popup);
    popup_reset(nfc_playlist->popup);
    popup_set_context(nfc_playlist->popup, nfc_playlist);
    popup_set_context(nfc_playlist->popup, nfc_playlist);
@@ -70,15 +23,15 @@ int32_t nfc_playlist_emulation_task(void* context) {
 
 
          char* file_path = (char*)furi_string_get_cstr(line);
          char* file_path = (char*)furi_string_get_cstr(line);
 
 
-         if (strlen(file_path) <= 1) {continue;}
+         if(strlen(file_path) <= 1) {continue;}
 
 
-         if (nfc_playlist->settings.emulate_delay > 0 && file_position != 0) {
+         if(nfc_playlist->settings.emulate_delay > 0 && file_position != 0) {
             popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop);
             popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
             int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
             do {
             do {
-               furi_string_printf(temp_counter_str,  "%ds", (time_counter_delay_ms/1000));
-               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop);
+               furi_string_printf(tmp_counter_str,  "%ds", (time_counter_delay_ms/1000));
+               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                furi_delay_ms(50);
                time_counter_delay_ms -= 50;
                time_counter_delay_ms -= 50;
             } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
             } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
@@ -86,41 +39,41 @@ int32_t nfc_playlist_emulation_task(void* context) {
             file_position++;
             file_position++;
          }
          }
 
 
-         if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;}
+         if(EmulationState != NfcPlaylistEmulationState_Emulating) {break;}
 
 
          char* file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path;
          char* file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path;
          char const* file_ext = &strrchr(file_path, '.')[1];
          char const* file_ext = &strrchr(file_path, '.')[1];
          int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);
          int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);
 
 
-         if (storage_file_exists(storage, file_path) == false) {
-            furi_string_printf(temp_header_str, "ERROR not found:\n %s", file_name);
-            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop);
+         if(storage_file_exists(storage, file_path) == false) {
+            furi_string_printf(tmp_header_str, "ERROR not found:\n%s", file_name);
+            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             do {
             do {
-               furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop);
+               furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
+               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                furi_delay_ms(50);
                time_counter_ms -= 50;
                time_counter_ms -= 50;
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else if (strcasestr(file_ext, "nfc") == NULL) {
          } else if (strcasestr(file_ext, "nfc") == NULL) {
-            furi_string_printf(temp_header_str, "ERROR invalid file:\n %s", file_name);
-            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop);
+            furi_string_printf(tmp_header_str, "ERROR invalid file:\n%s", file_name);
+            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             do {
             do {
-               furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop);
+               furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
+               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                furi_delay_ms(50);
                time_counter_ms -= 50;
                time_counter_ms -= 50;
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else {
          } else {
-            furi_string_printf(temp_header_str, "Emulating:\n %s", file_name);
-            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop);
+            furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name);
+            popup_set_header(nfc_playlist->popup, furi_string_get_cstr(tmp_header_str), 64, 10, AlignCenter, AlignTop);
             nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path);
             nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path);
             nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker);
             nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker);
             start_blink(nfc_playlist, NfcPlaylistLedState_Normal);
             start_blink(nfc_playlist, NfcPlaylistLedState_Normal);
             do {
             do {
-               furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop);
+               furi_string_printf(tmp_counter_str, "%ds", (time_counter_ms/1000));
+               popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                furi_delay_ms(50);
                furi_delay_ms(50);
                time_counter_ms -= 50;
                time_counter_ms -= 50;
             } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
             } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
@@ -140,11 +93,59 @@ int32_t nfc_playlist_emulation_task(void* context) {
    }
    }
 
 
    furi_string_free(line);
    furi_string_free(line);
-   furi_string_free(temp_header_str);
-   furi_string_free(temp_counter_str);
+   furi_string_free(tmp_header_str);
+   furi_string_free(tmp_counter_str);
    file_stream_close(stream);
    file_stream_close(stream);
    furi_record_close(RECORD_STORAGE);
    furi_record_close(RECORD_STORAGE);
    stream_free(stream);
    stream_free(stream);
 
 
    return 0;
    return 0;
+}
+
+void nfc_playlist_emulation_setup(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   nfc_playlist->thread = furi_thread_alloc_ex("NfcPlaylistEmulationWorker", 8192, nfc_playlist_emulation_task, nfc_playlist);
+   nfc_playlist->nfc_playlist_worker = nfc_playlist_worker_alloc();
+}
+
+void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist) {
+   furi_assert(nfc_playlist);
+   furi_thread_free(nfc_playlist->thread);
+   nfc_playlist_worker_free(nfc_playlist->nfc_playlist_worker);
+   nfc_playlist->thread = NULL;
+   nfc_playlist->nfc_playlist_worker = NULL;
+}
+
+void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist) {
+   furi_assert(nfc_playlist);
+   furi_thread_start(nfc_playlist->thread);
+}
+
+void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist) {
+   furi_assert(nfc_playlist);
+   furi_thread_join(nfc_playlist->thread);
+}
+
+void nfc_playlist_emulation_scene_on_enter(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   nfc_playlist_emulation_setup(nfc_playlist);
+   nfc_playlist_emulation_start(nfc_playlist);
+}
+
+bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event) {
+   UNUSED(context);
+   bool consumed = false;
+   if(event.event == 0 && EmulationState == NfcPlaylistEmulationState_Emulating) {
+      EmulationState = NfcPlaylistEmulationState_Canceled;
+      consumed = true;
+   }
+   return consumed;
+}
+
+void nfc_playlist_emulation_scene_on_exit(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   EmulationState = NfcPlaylistEmulationState_Stopped;
+   nfc_playlist_emulation_stop(nfc_playlist);
+   nfc_playlist_emulation_free(nfc_playlist);
+   popup_reset(nfc_playlist->popup);
 }
 }

+ 0 - 6
scences/emulation.h

@@ -13,12 +13,6 @@ void nfc_playlist_emulation_scene_on_enter(void* context);
 bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event);
 bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event);
 void nfc_playlist_emulation_scene_on_exit(void* context);
 void nfc_playlist_emulation_scene_on_exit(void* context);
 
 
-void nfc_playlist_emulation_setup(void* context);
-void nfc_playlist_emulation_free(NfcPlaylist* nfc_playlist);
-void nfc_playlist_emulation_start(NfcPlaylist* nfc_playlist);
-void nfc_playlist_emulation_stop(NfcPlaylist* nfc_playlist);
-int32_t nfc_playlist_emulation_task(void* context);
-
 typedef enum NfcPlaylistEmulationState {
 typedef enum NfcPlaylistEmulationState {
    NfcPlaylistEmulationState_Emulating,
    NfcPlaylistEmulationState_Emulating,
    NfcPlaylistEmulationState_Stopped,
    NfcPlaylistEmulationState_Stopped,

+ 18 - 20
scences/file_edit.c

@@ -1,25 +1,9 @@
 #include "nfc_playlist.h"
 #include "nfc_playlist.h"
 #include "scences/file_edit.h"
 #include "scences/file_edit.h"
 
 
-typedef enum {
-   NfcPlaylistMenuSelection_DeletePlaylist,
-   NfcPlaylistMenuSelection_RenamePlaylist
-} NfcPlaylistMenuSelection;
-
 void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) {
 void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
-   switch(index) {
-      case NfcPlaylistMenuSelection_DeletePlaylist: {
-         scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete);
-         break;
-      }
-      case NfcPlaylistMenuSelection_RenamePlaylist: {
-         scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename);
-         break;
-      }
-      default:
-         break;
-   }
+   scene_manager_handle_custom_event(nfc_playlist->scene_manager, index);
 }
 }
 
 
 void nfc_playlist_file_edit_scene_on_enter(void* context) {
 void nfc_playlist_file_edit_scene_on_enter(void* context) {
@@ -49,9 +33,23 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
 }
 }
 
 
 bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event) {
 bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event) {
-   UNUSED(event);
-   UNUSED(context);
-   return false;
+   NfcPlaylist* nfc_playlist = context;
+   bool consumed = false;
+   if(event.type == SceneManagerEventTypeCustom) {
+      switch(event.event) {
+         case NfcPlaylistMenuSelection_DeletePlaylist:
+            scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete);
+            consumed = true;
+            break;
+         case NfcPlaylistMenuSelection_RenamePlaylist:
+            scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename);
+            consumed = true;
+            break;
+         default:
+            break;
+      }
+   }
+   return consumed;
 }
 }
 
 
 void nfc_playlist_file_edit_scene_on_exit(void* context) {
 void nfc_playlist_file_edit_scene_on_exit(void* context) {

+ 6 - 1
scences/file_edit.h

@@ -6,4 +6,9 @@
 
 
 void nfc_playlist_file_edit_scene_on_enter(void* context);
 void nfc_playlist_file_edit_scene_on_enter(void* context);
 bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event);
 bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event);
-void nfc_playlist_file_edit_scene_on_exit(void* context);
+void nfc_playlist_file_edit_scene_on_exit(void* context);
+
+typedef enum {
+   NfcPlaylistMenuSelection_DeletePlaylist,
+   NfcPlaylistMenuSelection_RenamePlaylist
+} NfcPlaylistFileEditMenuSelection;

+ 12 - 13
scences/file_rename.c

@@ -4,26 +4,24 @@
 void nfc_playlist_file_rename_menu_callback(void* context) {
 void nfc_playlist_file_rename_menu_callback(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Storage* storage = furi_record_open(RECORD_STORAGE);
-   FuriString* new_file_path = furi_string_alloc();
+   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_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;
    char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path;
 
 
-   int file_path_size = (strlen(old_file_path) - strlen(old_file_name) + 1);
+   furi_string_printf(tmp_old_file_path, "%s", old_file_path);
+   furi_string_replace(tmp_old_file_path, old_file_name, "");
 
 
-   char* file_path = (char*)malloc(file_path_size);
-   snprintf(file_path, file_path_size, "%s", old_file_path);
+   furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->playlist_name);
 
 
-   furi_string_printf(new_file_path, "%s%s.txt", file_path, nfc_playlist->playlist_name);
-
-   if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) {
-      storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(new_file_path));
-      nfc_playlist->settings.file_path = new_file_path;
+   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));
    }
    }
-   free(file_path);
-   free(nfc_playlist->playlist_name);
    furi_record_close(RECORD_STORAGE);
    furi_record_close(RECORD_STORAGE);
-   furi_string_free(new_file_path);
+   furi_string_free(tmp_new_file_path);
+   furi_string_free(tmp_old_file_path);
 
 
    scene_manager_previous_scene(nfc_playlist->scene_manager);
    scene_manager_previous_scene(nfc_playlist->scene_manager);
 }
 }
@@ -34,7 +32,7 @@ void nfc_playlist_file_rename_scene_on_enter(void* context) {
    text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");
    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_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->playlist_name, 50, true);
    text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true);
-   view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
+   view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);   
 }
 }
 
 
 bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) {
 bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) {
@@ -46,4 +44,5 @@ bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent ev
 void nfc_playlist_file_rename_scene_on_exit(void* context) {
 void nfc_playlist_file_rename_scene_on_exit(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
    text_input_reset(nfc_playlist->text_input);
    text_input_reset(nfc_playlist->text_input);
+   free(nfc_playlist->playlist_name);
 }
 }

+ 1 - 30
scences/main_menu.c

@@ -1,38 +1,9 @@
 #include "nfc_playlist.h"
 #include "nfc_playlist.h"
 #include "scences/main_menu.h"
 #include "scences/main_menu.h"
 
 
-typedef enum {
-   NfcPlaylistEvent_ShowEmulatingPopup,
-   NfcPlaylistEvent_ShowFileSelect,
-   NfcPlaylistEvent_ShowFileEdit,
-   NfcPlaylistEvent_ShowSettings
-} NfcPlaylistMainMenuEvent;
-
-typedef enum {
-   NfcPlaylistMenuSelection_Start,
-   NfcPlaylistMenuSelection_FileSelect,
-   NfcPlaylistMenuSelection_FileEdit,
-   NfcPlaylistMenuSelection_Settings
-} NfcPlaylistMenuSelection;
-
 void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) {
 void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
-   switch(index) {
-      case NfcPlaylistMenuSelection_Start:
-         scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowEmulatingPopup);
-         break;
-      case NfcPlaylistMenuSelection_FileSelect:
-         scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileSelect);
-         break;
-      case NfcPlaylistMenuSelection_FileEdit:
-         scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileEdit);
-         break;
-      case NfcPlaylistMenuSelection_Settings:
-         scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowSettings);
-         break;
-      default:
-         break;
-   }
+   scene_manager_handle_custom_event(nfc_playlist->scene_manager, index);
 }
 }
 
 
 void nfc_playlist_main_menu_scene_on_enter(void* context) {
 void nfc_playlist_main_menu_scene_on_enter(void* context) {

+ 15 - 1
scences/main_menu.h

@@ -6,4 +6,18 @@
 
 
 void nfc_playlist_main_menu_scene_on_enter(void* context);
 void nfc_playlist_main_menu_scene_on_enter(void* context);
 bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event);
 bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event);
-void nfc_playlist_main_menu_scene_on_exit(void* context);
+void nfc_playlist_main_menu_scene_on_exit(void* context);
+
+typedef enum {
+   NfcPlaylistEvent_ShowEmulatingPopup,
+   NfcPlaylistEvent_ShowFileSelect,
+   NfcPlaylistEvent_ShowFileEdit,
+   NfcPlaylistEvent_ShowSettings
+} NfcPlaylistMainMenuEvent;
+
+typedef enum {
+   NfcPlaylistMenuSelection_Start,
+   NfcPlaylistMenuSelection_FileSelect,
+   NfcPlaylistMenuSelection_FileEdit,
+   NfcPlaylistMenuSelection_Settings
+} NfcPlaylistMainMenuMenuSelection;

+ 35 - 34
scences/settings.c

@@ -1,35 +1,9 @@
 #include "nfc_playlist.h"
 #include "nfc_playlist.h"
 #include "scences/settings.h"
 #include "scences/settings.h"
 
 
-typedef enum {
-   NfcPlaylistSettings_Timeout,
-   NfcPlaylistSettings_Delay,
-   NfcPlaylistSettings_LedIndicator,
-   NfcPlaylistSettings_Reset
-} NfcPlaylistMenuSelection;
-
 void nfc_playlist_settings_menu_callback(void* context, uint32_t index) {
 void nfc_playlist_settings_menu_callback(void* context, uint32_t index) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
-   FuriString* temp_str = furi_string_alloc();
-   if (index == NfcPlaylistSettings_Reset) {
-      nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
-      VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout);
-      variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
-      furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
-      variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str));
-
-      nfc_playlist->settings.emulate_delay = default_emulate_delay;
-      VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay);
-      variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
-      furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
-      variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str));
-
-      nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
-      VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator);
-      variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
-      variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
-   }
-   furi_string_free(temp_str);
+   scene_manager_handle_custom_event(nfc_playlist->scene_manager, index);
 }
 }
 
 
 void nfc_playlist_settings_options_change_callback(VariableItem* item) {
 void nfc_playlist_settings_options_change_callback(VariableItem* item) {
@@ -39,18 +13,16 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {
    uint8_t option_value_index = variable_item_get_current_value_index(item);
    uint8_t option_value_index = variable_item_get_current_value_index(item);
    FuriString* temp_str = furi_string_alloc();
    FuriString* temp_str = furi_string_alloc();
    switch(current_option) {
    switch(current_option) {
-      case NfcPlaylistSettings_Timeout: {
+      case NfcPlaylistSettings_Timeout:
          nfc_playlist->settings.emulate_timeout = option_value_index;
          nfc_playlist->settings.emulate_timeout = option_value_index;
          furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
          furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
          variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str));
          variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str));
          break;
          break;
-      }
-      case NfcPlaylistSettings_Delay: {
+      case NfcPlaylistSettings_Delay:
          nfc_playlist->settings.emulate_delay = option_value_index;
          nfc_playlist->settings.emulate_delay = option_value_index;
          furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
          furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
          variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str));
          variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str));
          break;
          break;
-      }
       case NfcPlaylistSettings_LedIndicator:
       case NfcPlaylistSettings_LedIndicator:
          nfc_playlist->settings.emulate_led_indicator = option_value_index;
          nfc_playlist->settings.emulate_led_indicator = option_value_index;
          variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
          variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
@@ -106,9 +78,38 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
 }
 }
 
 
 bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event) {
 bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event) {
-   UNUSED(context);
-   UNUSED(event);
-   return false;
+   NfcPlaylist* nfc_playlist = context;
+   bool consumed = false;
+   if (event.type == SceneManagerEventTypeCustom) {
+      switch(event.event) {
+         case NfcPlaylistSettings_Reset:
+            FuriString* temp_str = furi_string_alloc();
+
+            nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
+            VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout);
+            variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
+            furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
+            variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str));
+
+            nfc_playlist->settings.emulate_delay = default_emulate_delay;
+            VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay);
+            variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
+            furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
+            variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str));
+
+            nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
+            VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator);
+            variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
+            variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
+
+            furi_string_free(temp_str);
+            consumed = true;
+            break;
+         default:
+            break;
+      }
+   }
+   return consumed;
 }
 }
 
 
 void nfc_playlist_settings_scene_on_exit(void* context) {
 void nfc_playlist_settings_scene_on_exit(void* context) {

+ 8 - 1
scences/settings.h

@@ -6,4 +6,11 @@
 
 
 void nfc_playlist_settings_scene_on_enter(void* context);
 void nfc_playlist_settings_scene_on_enter(void* context);
 bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event);
 bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event);
-void nfc_playlist_settings_scene_on_exit(void* context);
+void nfc_playlist_settings_scene_on_exit(void* context);
+
+typedef enum {
+   NfcPlaylistSettings_Timeout,
+   NfcPlaylistSettings_Delay,
+   NfcPlaylistSettings_LedIndicator,
+   NfcPlaylistSettings_Reset
+} NfcPlaylistSettingsMenuSelection;