Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed May 23, 2024
1 parent 4396569 commit 416e22f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ As i know these firmwares are supported and working if you know any more please
- Add NFC Item (Adds the selected nfc item to the currently selected playlist)
- Remove NFC Item (Opens a menu allowing you to select a line to remove from the playlist)
- View playlist content (Allows you to view the contents of the playlist)
## Development plans/ideas:
Things i would like to add:
- Ability to remove cards from the playlist

These features are not guaranteed to be added but are being looked at as features to add
## Known issues
### Renaming/creating playlist
I know of an issue with these functions that can cause them to lock the viewport if you put in a name that is very long im looking into fixing this and finding a solution

Any feedback is welcome and would be very much appreciated
8 changes: 4 additions & 4 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

#include "scenes/nfc_playlist_scene.h"

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
#define PLAYLIST_NAME_LEN 100

typedef enum {
NfcPlaylistView_Submenu,
NfcPlaylistView_Popup,
Expand Down Expand Up @@ -72,10 +76,6 @@ static const int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;
static const bool default_skip_error = false;

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
#define PLAYLIST_NAME_LEN 100

typedef enum NfcPlaylistLedState {
NfcPlaylistLedState_Normal,
NfcPlaylistLedState_Error
Expand Down
23 changes: 12 additions & 11 deletions scenes/nfc_playlist_scene_name_new_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

void nfc_playlist_name_new_playlist_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriString* file_name = furi_string_alloc();

furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
FuriString* file_name = furi_string_alloc_printf("/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
char const* file_name_cstr = furi_string_get_cstr(file_name);

Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
if (storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW)) {
storage_file_close(file);
furi_string_swap(nfc_playlist->settings.playlist_path, file_name);
if (!storage_file_exists(storage, file_name_cstr)) {
if (storage_file_open(file, file_name_cstr, FSAM_READ_WRITE, FSOM_CREATE_NEW)) {
storage_file_close(file);
furi_string_swap(nfc_playlist->settings.playlist_path, file_name);
nfc_playlist->settings.playlist_length = 0;
}
}

nfc_playlist->settings.playlist_length = 0;

storage_file_free(file);
furi_string_free(file_name);
furi_record_close(RECORD_STORAGE);

furi_string_free(file_name);
scene_manager_previous_scene(nfc_playlist->scene_manager);
}

void nfc_playlist_name_new_playlist_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;

nfc_playlist->text_input_output = (char*)malloc(PLAYLIST_NAME_LEN);
nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN);
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
text_input_set_minimum_length(nfc_playlist->text_input, 1);
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_playlist_menu_callback, nfc_playlist, nfc_playlist->text_input_output, PLAYLIST_NAME_LEN, true);
Expand Down
10 changes: 6 additions & 4 deletions scenes/nfc_playlist_scene_playlist_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

void nfc_playlist_playlist_rename_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;
Storage* storage = furi_record_open(RECORD_STORAGE);

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;
Expand All @@ -11,12 +10,14 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) {
furi_string_replace(new_file_path, old_file_name, nfc_playlist->text_input_output);
furi_string_cat_str(new_file_path, ".txt");

if (storage_common_rename_safe(storage, old_file_path, furi_string_get_cstr(new_file_path)) == 0) {
Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) {
storage_common_rename(storage, old_file_path, furi_string_get_cstr(new_file_path));
furi_string_swap(nfc_playlist->settings.playlist_path, new_file_path);
}
furi_record_close(RECORD_STORAGE);

furi_string_free(new_file_path);
furi_record_close(RECORD_STORAGE);

scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
}
Expand All @@ -30,7 +31,8 @@ void nfc_playlist_playlist_rename_scene_on_enter(void* context) {
FuriString* tmp_file_name_furi = furi_string_alloc_set_str(tmp_file_name);
furi_string_replace(tmp_file_name_furi, ".txt", "");

nfc_playlist->text_input_output = strdup(furi_string_get_cstr(tmp_file_name_furi));
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);

text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");
Expand Down

0 comments on commit 416e22f

Please sign in to comment.