acegoal07 hace 1 año
padre
commit
2c140f1edd

+ 0 - 1
nfc_playlist.h

@@ -64,7 +64,6 @@ typedef struct {
    char* text_input_output;
    char* text_input_output;
    NotificationApp* notification;
    NotificationApp* notification;
    FuriThread* thread;
    FuriThread* thread;
-   FuriString* temp_furi_string;
    NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker;
    NfcPlaylistEmulationWorker* nfc_playlist_emulation_worker;
    NfcPlaylistSettings settings;
    NfcPlaylistSettings settings;
 } NfcPlaylist;
 } NfcPlaylist;

+ 6 - 5
scenes/nfc_playlist_scene_confirm_delete.c

@@ -10,7 +10,7 @@ void nfc_playlist_confirm_delete_menu_callback(GuiButtonType result, InputType t
 void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
 void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
 
 
-   char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.playlist_path);
+   char const* file_path = furi_string_get_cstr(nfc_playlist->settings.playlist_path);
    FuriString* temp_str = furi_string_alloc_printf("\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
    FuriString* temp_str = furi_string_alloc_printf("\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
    furi_string_replace(temp_str, ".txt", "");
    furi_string_replace(temp_str, ".txt", "");
 
 
@@ -30,12 +30,13 @@ bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent
       switch(event.event) {
       switch(event.event) {
          case GuiButtonTypeRight:
          case GuiButtonTypeRight:
             Storage* storage = furi_record_open(RECORD_STORAGE);
             Storage* storage = furi_record_open(RECORD_STORAGE);
-            storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.playlist_path));
-            nfc_playlist->settings.playlist_selected = false;
-            furi_string_reset(nfc_playlist->settings.playlist_path);
+            if (storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.playlist_path))) {
+               nfc_playlist->settings.playlist_selected = false;
+               furi_string_reset(nfc_playlist->settings.playlist_path);               
+            }
             furi_record_close(RECORD_STORAGE);
             furi_record_close(RECORD_STORAGE);
-            consumed = true;
             scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
             scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
+            consumed = true;
             break;
             break;
          default:
          default:
             scene_manager_previous_scene(nfc_playlist->scene_manager);
             scene_manager_previous_scene(nfc_playlist->scene_manager);

+ 0 - 6
scenes/nfc_playlist_scene_emulation.c

@@ -47,7 +47,6 @@ int32_t nfc_playlist_emulation_task(void* context) {
                time_counter_delay_ms -= 50;
                time_counter_delay_ms -= 50;
                furi_string_reset(tmp_counter_str);
                furi_string_reset(tmp_counter_str);
             };
             };
-            furi_string_reset(tmp_counter_str);
          } else if (nfc_playlist->settings.emulate_delay > 0) {
          } else if (nfc_playlist->settings.emulate_delay > 0) {
             skip_delay = false;
             skip_delay = false;
             file_position++;
             file_position++;
@@ -72,7 +71,6 @@ int32_t nfc_playlist_emulation_task(void* context) {
                popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                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;
-               furi_string_reset(tmp_counter_str);
             };
             };
          } else if(!storage_file_exists(storage, file_path)) {
          } else if(!storage_file_exists(storage, file_path)) {
             if(nfc_playlist->settings.skip_error) {
             if(nfc_playlist->settings.skip_error) {
@@ -87,7 +85,6 @@ int32_t nfc_playlist_emulation_task(void* context) {
                popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                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;
-               furi_string_reset(tmp_counter_str);
             };
             };
          } else {
          } else {
             furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name);
             furi_string_printf(tmp_header_str, "Emulating:\n%s", file_name);
@@ -100,13 +97,10 @@ int32_t nfc_playlist_emulation_task(void* context) {
                popup_set_text(nfc_playlist->popup, furi_string_get_cstr(tmp_counter_str), 64, 50, AlignCenter, AlignTop);
                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;
-               furi_string_reset(tmp_counter_str);
             };
             };
             nfc_playlist_emulation_worker_stop(nfc_playlist->nfc_playlist_emulation_worker);
             nfc_playlist_emulation_worker_stop(nfc_playlist->nfc_playlist_emulation_worker);
             nfc_playlist_emulation_worker_clear_nfc_data(nfc_playlist->nfc_playlist_emulation_worker);
             nfc_playlist_emulation_worker_clear_nfc_data(nfc_playlist->nfc_playlist_emulation_worker);
          }
          }
-         furi_string_reset(tmp_header_str);
-         furi_string_reset(tmp_counter_str);
       }
       }
       popup_reset(nfc_playlist->popup);
       popup_reset(nfc_playlist->popup);
       if (nfc_playlist->settings.playlist_length == 0) {
       if (nfc_playlist->settings.playlist_length == 0) {

+ 5 - 4
scenes/nfc_playlist_scene_nfc_remove.c

@@ -17,17 +17,18 @@ void nfc_playlist_nfc_remove_options_change_callback(VariableItem* item) {
 
 
    uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list);
    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);
    uint8_t option_value_index = variable_item_get_current_value_index(item);
-   FuriString* tmp_str = furi_string_alloc();
+   
    switch(current_option) {
    switch(current_option) {
-      case NfcPlaylistSettings_LineSelector:
+      case NfcPlaylistSettings_LineSelector: {
          selected_line = option_value_index + 1;
          selected_line = option_value_index + 1;
-         furi_string_printf(tmp_str, "%d", selected_line);
+         FuriString* tmp_str = furi_string_alloc_printf("%d", selected_line);
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
+         furi_string_free(tmp_str);
          break;
          break;
+      }
       default:
       default:
          break;
          break;
    }
    }
-   furi_string_free(tmp_str);
 }
 }
 
 
 void nfc_playlist_nfc_remove_scene_on_enter(void* context) {
 void nfc_playlist_nfc_remove_scene_on_enter(void* context) {

+ 6 - 10
scenes/nfc_playlist_scene_playlist_rename.c

@@ -3,11 +3,9 @@
 void nfc_playlist_playlist_rename_menu_callback(void* context) {
 void nfc_playlist_playlist_rename_menu_callback(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
 
 
-   char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.playlist_path);
-   char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path;
-
+   char const* old_file_path = furi_string_get_cstr(nfc_playlist->settings.playlist_path);
    FuriString* new_file_path = furi_string_alloc_set(nfc_playlist->settings.playlist_path);
    FuriString* new_file_path = furi_string_alloc_set(nfc_playlist->settings.playlist_path);
-   furi_string_replace(new_file_path, old_file_name, nfc_playlist->text_input_output);
+   furi_string_replace(new_file_path, strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path, nfc_playlist->text_input_output);
    furi_string_cat_str(new_file_path, ".txt");
    furi_string_cat_str(new_file_path, ".txt");
    
    
    Storage* storage = furi_record_open(RECORD_STORAGE);
    Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -27,14 +25,12 @@ void nfc_playlist_playlist_rename_scene_on_enter(void* context) {
    NfcPlaylist* nfc_playlist = context;
    NfcPlaylist* nfc_playlist = context;
 
 
    char const* tmp_file_path = furi_string_get_cstr(nfc_playlist->settings.playlist_path);
    char const* tmp_file_path = furi_string_get_cstr(nfc_playlist->settings.playlist_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", "");
+   FuriString* tmp_file_name = furi_string_alloc_set_str(strchr(tmp_file_path, '/') != NULL ? &strrchr(tmp_file_path, '/')[1] : tmp_file_path);
+   furi_string_replace(tmp_file_name, ".txt", "");
 
 
    nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN);
    nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN);
-   strcpy(nfc_playlist->text_input_output, furi_string_get_cstr(tmp_file_name_furi));
-   furi_string_free(tmp_file_name_furi);
+   strcpy(nfc_playlist->text_input_output, furi_string_get_cstr(tmp_file_name));
+   furi_string_free(tmp_file_name);
 
 
    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);

+ 10 - 7
scenes/nfc_playlist_scene_settings.c

@@ -18,18 +18,22 @@ 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 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);
    uint8_t option_value_index = variable_item_get_current_value_index(item);
-   FuriString* tmp_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(tmp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
+         FuriString* tmp_str = furi_string_alloc_printf("%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
-         break;
-      case NfcPlaylistSettings_Delay:
+         furi_string_free(tmp_str);
+         break;         
+      }
+      case NfcPlaylistSettings_Delay: {
          nfc_playlist->settings.emulate_delay = option_value_index;
          nfc_playlist->settings.emulate_delay = option_value_index;
-         furi_string_printf(tmp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
+         FuriString* tmp_str = furi_string_alloc_printf("%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
          variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_str));
+         furi_string_free(tmp_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");
@@ -41,7 +45,6 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {
       default:
       default:
          break;
          break;
    }
    }
-   furi_string_free(tmp_str);
 }
 }
 
 
 void nfc_playlist_settings_scene_on_enter(void* context) {
 void nfc_playlist_settings_scene_on_enter(void* context) {