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

Merge pull request #16 from acegoal07/dev

Dev
acegoal07 1 год назад
Родитель
Сommit
294fc6a34e

+ 5 - 4
README.md

@@ -1,6 +1,5 @@
 # FlipperZero_NFC_Playlist:
 The idea behind this app is to allow for you to test multiple copies of NFC's at once as a bulk test
-
 ## How it works:
 When starting the app you are greeted by a select file option where you choose the playlist you wanna run.
 
@@ -10,16 +9,18 @@ All the playlists should be placed in ext/apps_data/nfc_playlist and an example
 /ext/nfc/link2.nfc
 ```
 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
-
+## 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>
+- <a href="https://github.com/Next-Flip/Momentum-Firmware">Momentum</a>
+- <a href="https://github.com/RogueMaster/flipperzero-firmware-wPlugins">RogueMaster</a>
 ## Settings:
 - Emulate time (How long the NFC card will be emulated for)
 - Delay time (How long the gap between the cards will be)
 - LED indicator (Whether or not the LED's will be on)
 - Reset settings (Puts all the settings back to the defaults)
-
 ## Playlist editor:
 - Delete playlist (Deletes the selected playlist)
 - Rename playlist (Renames the selected playlist the new name provided)

+ 1 - 1
application.fam

@@ -8,7 +8,7 @@ App(
     fap_category="NFC",
     fap_author="@acegoal07",
     fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
-    fap_version="1.5",
+    fap_version="1.6",
     fap_icon="assets/icon.png",
     fap_private_libs=[
         Lib(

+ 18 - 8
nfc_playlist.c

@@ -7,7 +7,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
    nfc_playlist_emulation_scene_on_enter,
    nfc_playlist_file_select_scene_on_enter,
    nfc_playlist_file_edit_scene_on_enter,
-   nfc_playlist_text_input_scene_on_enter
+   nfc_playlist_file_rename_scene_on_enter,
+   nfc_playlist_confirm_delete_scene_on_enter
 };
 
 static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
@@ -16,7 +17,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE
    nfc_playlist_emulation_scene_on_event,
    nfc_playlist_file_select_scene_on_event,
    nfc_playlist_file_edit_scene_on_event,
-   nfc_playlist_text_input_scene_on_event
+   nfc_playlist_file_rename_scene_on_event,
+   nfc_playlist_confirm_delete_scene_on_event
 };
 
 static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
@@ -25,7 +27,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
    nfc_playlist_emulation_scene_on_exit,
    nfc_playlist_file_select_scene_on_exit,
    nfc_playlist_file_edit_scene_on_exit,
-   nfc_playlist_text_input_scene_on_exit
+   nfc_playlist_file_rename_scene_on_exit,
+   nfc_playlist_confirm_delete_scene_on_exit
 };
 
 static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
@@ -55,6 +58,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
    view_dispatcher_enable_queue(nfc_playlist->view_dispatcher);
    nfc_playlist->variable_item_list = variable_item_list_alloc();
    nfc_playlist->submenu = submenu_alloc();
+   nfc_playlist->widget= widget_alloc();
 
    nfc_playlist->settings.base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/");
    nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
@@ -77,7 +81,8 @@ static NfcPlaylist* nfc_playlist_alloc() {
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup));
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser));
    view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
-   view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input));
+   view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename, text_input_get_view(nfc_playlist->text_input));
+   view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget));
 
    Storage* storage = furi_record_open(RECORD_STORAGE);
    if (!storage_common_exists(storage, "/ext/apps_data/nfc_playlist")) {
@@ -90,23 +95,28 @@ static NfcPlaylist* nfc_playlist_alloc() {
 
 static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
    furi_assert(nfc_playlist);
-   scene_manager_free(nfc_playlist->scene_manager);
+
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect);
    view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
-   view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
+   view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
+   view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
+
+   scene_manager_free(nfc_playlist->scene_manager);
    view_dispatcher_free(nfc_playlist->view_dispatcher);
    variable_item_list_free(nfc_playlist->variable_item_list);
    submenu_free(nfc_playlist->submenu);
+   widget_free(nfc_playlist->widget);
+
+   furi_record_close(RECORD_NOTIFICATION);
    file_browser_free(nfc_playlist->file_browser);
    text_input_free(nfc_playlist->text_input);
    popup_free(nfc_playlist->popup);
-   furi_record_close(RECORD_NOTIFICATION);
+
    furi_string_free(nfc_playlist->settings.base_file_path);
    furi_string_free(nfc_playlist->settings.file_path);
-   free(nfc_playlist->playlist_name);
    free(nfc_playlist);
 }
 

+ 7 - 2
nfc_playlist.h

@@ -11,6 +11,8 @@
 #include <gui/modules/submenu.h>
 #include <gui/modules/file_browser.h>
 #include <gui/modules/text_input.h>
+#include <gui/modules/widget.h>
+#include <gui/modules/widget_elements/widget_element.h>
 #include <notification/notification_messages.h>
 #include <nfc_playlist_worker.h>
 
@@ -20,7 +22,8 @@ typedef enum {
    NfcPlaylistView_Popup,
    NfcPlaylistView_FileSelect,
    NfcPlaylistView_FileEdit,
-   NfcPlaylistView_TextInput
+   NfcPlaylistView_FileRename,
+   NfcPlaylistView_ConfirmDelete
 } NfcPlayScenesView;
 
 typedef enum {
@@ -29,7 +32,8 @@ typedef enum {
    NfcPlaylistScene_EmulatingPopup,
    NfcPlaylistScene_FileSelect,
    NfcPlaylistScene_FileEdit,
-   NfcPlaylistScene_TextInput,
+   NfcPlaylistScene_FileRename,
+   NfcPlaylistScene_ConfirmDelete,
    NfcPlaylistScene_count
 } NfcPlaylistScene;
 
@@ -51,6 +55,7 @@ typedef struct {
    TextInput* text_input;
    Submenu* submenu;
    Popup* popup;
+   Widget* widget;
    NotificationApp* notification;
    FuriThread* thread;
    NfcPlaylistWorker* nfc_playlist_worker;

+ 2 - 1
nfc_playlist_i.h

@@ -4,4 +4,5 @@
 #include "scences/emulation.h"
 #include "scences/file_select.h"
 #include "scences/file_edit.h"
-#include "scences/text_input.h"
+#include "scences/file_rename.h"
+#include "scences/confirm_delete.h"

+ 53 - 0
scences/confirm_delete.c

@@ -0,0 +1,53 @@
+#include "nfc_playlist.h"
+#include "scences/confirm_delete.h"
+
+void nfc_playlist_confirm_delete_menu_callback(GuiButtonType result, InputType type, void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   if(type == InputTypeShort) {
+      view_dispatcher_send_custom_event(nfc_playlist->view_dispatcher, result);
+   }
+}
+
+void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+
+   FuriString* temp_str = furi_string_alloc();
+   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_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_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
+   widget_add_button_element(nfc_playlist->widget, GuiButtonTypeRight, "Delete", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
+
+   furi_string_free(temp_str);
+
+   view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
+}
+
+bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) {
+   NfcPlaylist* nfc_playlist = context;
+   bool consumed = false;
+   if(event.type == SceneManagerEventTypeCustom) {
+      switch(event.event) {
+         case GuiButtonTypeRight:
+            Storage* storage = furi_record_open(RECORD_STORAGE);
+            storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
+            nfc_playlist->settings.file_selected = false;
+            nfc_playlist->settings.file_selected_check = false;
+            nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
+            furi_record_close(RECORD_STORAGE);
+            consumed = true;
+            break;
+         default:
+            break;
+      }
+      scene_manager_previous_scene(nfc_playlist->scene_manager);
+   }
+   return consumed;
+}
+
+void nfc_playlist_confirm_delete_scene_on_exit(void* context) {
+   NfcPlaylist* nfc_playlist = context;
+   widget_reset(nfc_playlist->widget);
+}

+ 10 - 0
scences/confirm_delete.h

@@ -0,0 +1,10 @@
+#pragma once
+#include <furi.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/widget.h>
+#include <storage/storage.h>
+
+void nfc_playlist_confirm_delete_scene_on_enter(void* context);
+bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event);
+void nfc_playlist_confirm_delete_scene_on_exit(void* context);

+ 70 - 75
scences/emulation.c

@@ -3,59 +3,14 @@
 
 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) {
    NfcPlaylist* nfc_playlist = context;
 
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Stream* stream = file_stream_alloc(storage);
    FuriString* line = furi_string_alloc();
+   FuriString* tmp_header_str = furi_string_alloc();
+   FuriString* tmp_counter_str = furi_string_alloc();
 
    popup_reset(nfc_playlist->popup);
    popup_set_context(nfc_playlist->popup, nfc_playlist);
@@ -68,16 +23,15 @@ int32_t nfc_playlist_emulation_task(void* context) {
 
          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);
             start_blink(nfc_playlist, NfcPlaylistLedState_Error);
             int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
             do {
-               char display_text[10];
-               snprintf(display_text, 10, "%ds", (time_counter_delay_ms/1000));
-               popup_set_text(nfc_playlist->popup, display_text, 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);
                time_counter_delay_ms -= 50;
             } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
@@ -85,50 +39,41 @@ int32_t nfc_playlist_emulation_task(void* context) {
             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 const* file_ext = &strrchr(file_path, '.')[1];
          int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);
 
-         if (storage_file_exists(storage, file_path) == false) {
-            int popup_header_text_size = strlen(file_name) + 18;
-            char popup_header_text[popup_header_text_size];
-            snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name);
-            popup_set_header(nfc_playlist->popup, popup_header_text, 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);
             do {
-               char popup_text[10];
-               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, popup_text, 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);
                time_counter_ms -= 50;
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else if (strcasestr(file_ext, "nfc") == NULL) {
-            int popup_header_text_size = strlen(file_name) + 21;
-            char popup_header_text[popup_header_text_size];
-            snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name);
-            popup_set_header(nfc_playlist->popup, popup_header_text, 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);
             do {
-               char popup_text[10];
-               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, popup_text, 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);
                time_counter_ms -= 50;
             } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
          } else {
-            int popup_header_text_size = strlen(file_name) + 12;
-            char popup_header_text[popup_header_text_size];
-            snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "Emulating:", file_name);
-            popup_set_header(nfc_playlist->popup, popup_header_text, 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_start(nfc_playlist->nfc_playlist_worker);
             start_blink(nfc_playlist, NfcPlaylistLedState_Normal);
             do {
-               char popup_text[10];
-               snprintf(popup_text, 10, "%ds", (time_counter_ms/1000));
-               popup_set_text(nfc_playlist->popup, popup_text, 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);
                time_counter_ms -= 50;
             } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating);
@@ -148,9 +93,59 @@ int32_t nfc_playlist_emulation_task(void* context) {
    }
 
    furi_string_free(line);
+   furi_string_free(tmp_header_str);
+   furi_string_free(tmp_counter_str);
    file_stream_close(stream);
    furi_record_close(RECORD_STORAGE);
    stream_free(stream);
 
    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 - 7
scences/emulation.h

@@ -5,7 +5,6 @@
 #include <toolbox/stream/file_stream.h>
 #include <lib/worker/nfc_playlist_worker.h>
 #include <lib/led/nfc_playlist_led.h>
-#include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/popup.h>
@@ -14,12 +13,6 @@ void nfc_playlist_emulation_scene_on_enter(void* context);
 bool nfc_playlist_emulation_scene_on_event(void* context, SceneManagerEvent event);
 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 {
    NfcPlaylistEmulationState_Emulating,
    NfcPlaylistEmulationState_Stopped,

+ 18 - 27
scences/file_edit.c

@@ -1,32 +1,9 @@
 #include "nfc_playlist.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) {
    NfcPlaylist* nfc_playlist = context;
-   Storage* storage = furi_record_open(RECORD_STORAGE);
-   switch(index) {
-      case NfcPlaylistMenuSelection_DeletePlaylist: {
-         storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
-         nfc_playlist->settings.file_selected = false;
-         nfc_playlist->settings.file_selected_check = false;
-         nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
-         scene_manager_previous_scene(nfc_playlist->scene_manager);
-         break;
-      }
-      case NfcPlaylistMenuSelection_RenamePlaylist: {
-         scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_TextInput);
-         break;
-      }
-      default: {
-         break;
-      }
-   }
-   furi_record_close(RECORD_STORAGE);
+   scene_manager_handle_custom_event(nfc_playlist->scene_manager, index);
 }
 
 void nfc_playlist_file_edit_scene_on_enter(void* context) {
@@ -56,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) {
-   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) {

+ 6 - 5
scences/file_edit.h

@@ -1,13 +1,14 @@
 #pragma once
 #include <furi.h>
-#include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/submenu.h>
-#include <storage/storage.h>
-#include <toolbox/stream/stream.h>
-#include <toolbox/stream/file_stream.h>
 
 void nfc_playlist_file_edit_scene_on_enter(void* context);
 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;

+ 18 - 22
scences/text_input.c → scences/file_rename.c

@@ -1,52 +1,48 @@
 #include "nfc_playlist.h"
-#include "scences/text_input.h"
+#include "scences/file_rename.h"
 
-void nfc_playlist_text_input_menu_callback(void* context) {
+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;
 
-   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);
 
-   int new_file_path_size = (strlen(nfc_playlist->playlist_name) + strlen(".txt") + file_path_size + 1);
-
-   char* new_file_name = (char*)malloc(new_file_path_size);
-   snprintf(new_file_name, new_file_path_size, "%s%s%s", file_path, nfc_playlist->playlist_name, ".txt");
-
-   if (!storage_file_exists(storage, new_file_name)) {
-      storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_name);
-      nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_name);
+   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(new_file_name);
-   free(file_path);
-   free(nfc_playlist->playlist_name);
    furi_record_close(RECORD_STORAGE);
+   furi_string_free(tmp_new_file_path);
+   furi_string_free(tmp_old_file_path);
 
    scene_manager_previous_scene(nfc_playlist->scene_manager);
 }
 
-void nfc_playlist_text_input_scene_on_enter(void* context) {
+void nfc_playlist_file_rename_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
    nfc_playlist->playlist_name = (char*)malloc(50);
    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_text_input_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true);
-   view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
+   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);   
 }
 
-bool nfc_playlist_text_input_scene_on_event(void* context, SceneManagerEvent event) {
+bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) {
    UNUSED(context);
    UNUSED(event);
    return false;
 }
 
-void nfc_playlist_text_input_scene_on_exit(void* context) {
+void nfc_playlist_file_rename_scene_on_exit(void* context) {
    NfcPlaylist* nfc_playlist = context;
    text_input_reset(nfc_playlist->text_input);
+   free(nfc_playlist->playlist_name);
 }

+ 10 - 0
scences/file_rename.h

@@ -0,0 +1,10 @@
+#pragma once
+#include <furi.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/text_input.h>
+#include <storage/storage.h>
+
+void nfc_playlist_file_rename_scene_on_enter(void* context);
+bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event);
+void nfc_playlist_file_rename_scene_on_exit(void* context);

+ 0 - 1
scences/file_select.h

@@ -1,6 +1,5 @@
 #pragma once
 #include <furi.h>
-#include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/file_browser.h>

+ 4 - 33
scences/main_menu.c

@@ -1,38 +1,9 @@
 #include "nfc_playlist.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) {
    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) {
@@ -78,9 +49,9 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
 }
 
 bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event) {
-    NfcPlaylist* nfc_playlist = context;
-    bool consumed = false;
-    if (event.type == SceneManagerEventTypeCustom) {
+   NfcPlaylist* nfc_playlist = context;
+   bool consumed = false;
+   if (event.type == SceneManagerEventTypeCustom) {
       switch(event.event) {
          case NfcPlaylistEvent_ShowEmulatingPopup:
             scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_EmulatingPopup);

+ 15 - 2
scences/main_menu.h

@@ -1,10 +1,23 @@
 #pragma once
 #include <furi.h>
-#include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/submenu.h>
 
 void nfc_playlist_main_menu_scene_on_enter(void* context);
 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;

+ 48 - 47
scences/settings.c

@@ -1,35 +1,9 @@
 #include "nfc_playlist.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) {
    NfcPlaylist* nfc_playlist = context;
-   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);
-      char emulation_timeout_settings_text[3];
-      snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
-      variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
-
-      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);
-      char emulation_delay_settings_text[3];
-      snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
-      variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
-
-      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");
-   }
+   scene_manager_handle_custom_event(nfc_playlist->scene_manager, index);
 }
 
 void nfc_playlist_settings_options_change_callback(VariableItem* item) {
@@ -37,22 +11,18 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {
 
    uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list);
    uint8_t option_value_index = variable_item_get_current_value_index(item);
-
+   FuriString* temp_str = furi_string_alloc();
    switch(current_option) {
-      case NfcPlaylistSettings_Timeout: {
+      case NfcPlaylistSettings_Timeout:
          nfc_playlist->settings.emulate_timeout = option_value_index;
-         char emulate_timeout_text[3];
-         snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]);
-         variable_item_set_current_value_text(item, (char*)emulate_timeout_text);
+         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));
          break;
-      }
-      case NfcPlaylistSettings_Delay: {
+      case NfcPlaylistSettings_Delay:
          nfc_playlist->settings.emulate_delay = option_value_index;
-         char emulate_delay_text[3];
-         snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]);
-         variable_item_set_current_value_text(item, (char*)emulate_delay_text);
+         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));
          break;
-      }
       case NfcPlaylistSettings_LedIndicator:
          nfc_playlist->settings.emulate_led_indicator = option_value_index;
          variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
@@ -60,10 +30,12 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {
       default:
          break;
    }
+   furi_string_free(temp_str);
 }
 
 void nfc_playlist_settings_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
+   FuriString* temp_str = furi_string_alloc();
 
    variable_item_list_set_header(nfc_playlist->variable_item_list, "Settings");
 
@@ -74,9 +46,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
       nfc_playlist_settings_options_change_callback,
       nfc_playlist);
    variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
-   char emulation_timeout_settings_text[3];
-   snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
-   variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
+   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));
 
    VariableItem* emulation_delay_settings = variable_item_list_add(
       nfc_playlist->variable_item_list,
@@ -85,9 +56,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
       nfc_playlist_settings_options_change_callback,
       nfc_playlist);
    variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
-   char emulation_delay_settings_text[3];
-   snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
-   variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
+   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));
 
    VariableItem* emulation_led_indicator_settings = variable_item_list_add(
       nfc_playlist->variable_item_list,
@@ -102,13 +72,44 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
 
    variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist);
 
+   furi_string_free(temp_str);
+
    view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
 }
 
 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) {

+ 8 - 2
scences/settings.h

@@ -1,10 +1,16 @@
 #pragma once
 #include <furi.h>
-#include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/variable_item_list.h>
 
 void nfc_playlist_settings_scene_on_enter(void* context);
 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;

+ 0 - 13
scences/text_input.h

@@ -1,13 +0,0 @@
-#pragma once
-#include <furi.h>
-#include <string.h>
-#include <gui/gui.h>
-#include <gui/view_dispatcher.h>
-#include <gui/scene_manager.h>
-#include <gui/modules/file_browser.h>
-#include <gui/modules/text_input.h>
-#include <storage/storage.h>
-
-void nfc_playlist_text_input_scene_on_enter(void* context);
-bool nfc_playlist_text_input_scene_on_event(void* context, SceneManagerEvent event);
-void nfc_playlist_text_input_scene_on_exit(void* context);