From f19c9113b114e131bba5012cfee095a4115a8699 Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Mon, 19 Dec 2022 20:30:30 +0100 Subject: [PATCH 1/6] Weather App update --- fbt_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbt_options.py b/fbt_options.py index e4f8ee6ce..1ec55495e 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -14,7 +14,7 @@ DEBUG = 0 # Suffix to add to files when building distribution # If OS environment has DIST_SUFFIX set, it will be used instead -DIST_SUFFIX = "CC_CL-0019_12192022" +DIST_SUFFIX = "CC_CL-0020_12192022" # Coprocessor firmware COPRO_OB_DATA = "scripts/ob.data" From fa87216a1e98a9a6a7ad3c25908ede321fe2af1c Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Mon, 19 Dec 2022 21:57:48 +0200 Subject: [PATCH 2/6] [FL-2970] Untangle NFC_APP_FOLDER from nfc_device (#2124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Untangle NFC_APP_FOLDER from nfc_device * Make the folder an internal part of the nfc device struct * Move the NFC folder definition to the nfc allocator * Move the NFC folder definition to the allocator in the nfc magic FAP * Replace furi_string_printf with furi_string_set for folder allocation and handle the cases when folder has no slashes * Build and allocation fixes Co-authored-by: あく --- applications/main/nfc/nfc.c | 1 + applications/main/nfc/nfc_i.h | 1 + applications/plugins/nfc_magic/nfc_magic.c | 1 + applications/plugins/nfc_magic/nfc_magic_i.h | 2 + lib/nfc/nfc_device.c | 58 ++++++++++++++++---- lib/nfc/nfc_device.h | 2 +- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/applications/main/nfc/nfc.c b/applications/main/nfc/nfc.c index 0dd071bc4..6e6dc4dcc 100644 --- a/applications/main/nfc/nfc.c +++ b/applications/main/nfc/nfc.c @@ -46,6 +46,7 @@ Nfc* nfc_alloc() { // Nfc device nfc->dev = nfc_device_alloc(); + furi_string_set(nfc->dev->folder, NFC_APP_FOLDER); // Open GUI record nfc->gui = furi_record_open(RECORD_GUI); diff --git a/applications/main/nfc/nfc_i.h b/applications/main/nfc/nfc_i.h index d49b84766..f7e489902 100644 --- a/applications/main/nfc/nfc_i.h +++ b/applications/main/nfc/nfc_i.h @@ -44,6 +44,7 @@ ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST); #define NFC_TEXT_STORE_SIZE 128 +#define NFC_APP_FOLDER ANY_PATH("nfc") typedef enum { NfcRpcStateIdle, diff --git a/applications/plugins/nfc_magic/nfc_magic.c b/applications/plugins/nfc_magic/nfc_magic.c index 38eecba6a..e4e0ffde0 100644 --- a/applications/plugins/nfc_magic/nfc_magic.c +++ b/applications/plugins/nfc_magic/nfc_magic.c @@ -49,6 +49,7 @@ NfcMagic* nfc_magic_alloc() { // Nfc device nfc_magic->nfc_dev = nfc_device_alloc(); + furi_string_set(nfc_magic->nfc_dev->folder, NFC_APP_FOLDER); // Open GUI record nfc_magic->gui = furi_record_open(RECORD_GUI); diff --git a/applications/plugins/nfc_magic/nfc_magic_i.h b/applications/plugins/nfc_magic/nfc_magic_i.h index 01b300826..378912e5b 100644 --- a/applications/plugins/nfc_magic/nfc_magic_i.h +++ b/applications/plugins/nfc_magic/nfc_magic_i.h @@ -27,6 +27,8 @@ #include #include "nfc_magic_icons.h" +#define NFC_APP_FOLDER ANY_PATH("nfc") + enum NfcMagicCustomEvent { // Reserve first 100 events for button types and indexes, starting from 0 NfcMagicCustomEventReserved = 100, diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 3ab10a4f6..49eebc37d 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -27,6 +27,7 @@ NfcDevice* nfc_device_alloc() { nfc_dev->dialogs = furi_record_open(RECORD_DIALOGS); nfc_dev->load_path = furi_string_alloc(); nfc_dev->dev_data.parsed_data = furi_string_alloc(); + nfc_dev->folder = furi_string_alloc(); // Rename cache folder name for backward compatibility if(storage_common_stat(nfc_dev->storage, "/ext/nfc/cache", NULL) == FSE_OK) { @@ -42,6 +43,7 @@ void nfc_device_free(NfcDevice* nfc_dev) { furi_record_close(RECORD_DIALOGS); furi_string_free(nfc_dev->load_path); furi_string_free(nfc_dev->dev_data.parsed_data); + furi_string_free(nfc_dev->folder); free(nfc_dev); } @@ -1018,6 +1020,16 @@ static void nfc_device_get_shadow_path(FuriString* orig_path, FuriString* shadow furi_string_cat_printf(shadow_path, "%s", NFC_APP_SHADOW_EXTENSION); } +static void nfc_device_get_folder_from_path(FuriString* path, FuriString* folder) { + size_t last_slash = furi_string_search_rchar(path, '/'); + if(last_slash == FURI_STRING_FAILURE) { + // No slashes in the path, treat the whole path as a folder + furi_string_set(folder, path); + } else { + furi_string_set_n(folder, path, 0, last_slash); + } +} + bool nfc_device_save(NfcDevice* dev, const char* dev_name) { furi_assert(dev); @@ -1028,10 +1040,19 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { temp_str = furi_string_alloc(); do { - // Create nfc directory if necessary - if(!storage_simply_mkdir(dev->storage, NFC_APP_FOLDER)) break; + // Create directory if necessary + FuriString* folder = furi_string_alloc(); + // Get folder from filename (filename is in the form of "folder/filename.nfc", so the folder is "folder/") + furi_string_set(temp_str, dev_name); + // Get folder from filename + nfc_device_get_folder_from_path(temp_str, folder); + FURI_LOG_I("Nfc", "Saving to folder %s", furi_string_get_cstr(folder)); + if(!storage_simply_mkdir(dev->storage, furi_string_get_cstr(folder))) { + FURI_LOG_E("Nfc", "Failed to create folder %s", furi_string_get_cstr(folder)); + break; + } + furi_string_free(folder); // First remove nfc device file if it was saved - furi_string_printf(temp_str, "%s", dev_name); // Open file if(!flipper_format_file_open_always(file, furi_string_get_cstr(temp_str))) break; // Write header @@ -1199,10 +1220,9 @@ bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog) { bool nfc_file_select(NfcDevice* dev) { furi_assert(dev); + const char* folder = furi_string_get_cstr(dev->folder); // Input events and views are managed by file_browser - FuriString* nfc_app_folder; - nfc_app_folder = furi_string_alloc_set(NFC_APP_FOLDER); const DialogsFileBrowserOptions browser_options = { .extension = NFC_APP_EXTENSION, @@ -1212,13 +1232,12 @@ bool nfc_file_select(NfcDevice* dev) { .hide_ext = true, .item_loader_callback = NULL, .item_loader_context = NULL, - .base_path = NFC_APP_FOLDER, + .base_path = folder, }; bool res = dialog_file_browser_show(dev->dialogs, dev->load_path, dev->load_path, &browser_options); - furi_string_free(nfc_app_folder); if(res) { FuriString* filename; filename = furi_string_alloc(); @@ -1271,7 +1290,11 @@ bool nfc_device_delete(NfcDevice* dev, bool use_load_path) { furi_string_set(file_path, dev->load_path); } else { furi_string_printf( - file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION); + file_path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_EXTENSION); } if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break; // Delete shadow file if it exists @@ -1280,7 +1303,11 @@ bool nfc_device_delete(NfcDevice* dev, bool use_load_path) { nfc_device_get_shadow_path(dev->load_path, file_path); } else { furi_string_printf( - file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION); + file_path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_SHADOW_EXTENSION); } if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break; } @@ -1309,14 +1336,23 @@ bool nfc_device_restore(NfcDevice* dev, bool use_load_path) { nfc_device_get_shadow_path(dev->load_path, path); } else { furi_string_printf( - path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION); + path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_SHADOW_EXTENSION); } if(!storage_simply_remove(dev->storage, furi_string_get_cstr(path))) break; dev->shadow_file_exist = false; if(use_load_path && !furi_string_empty(dev->load_path)) { furi_string_set(path, dev->load_path); } else { - furi_string_printf(path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION); + furi_string_printf( + path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_EXTENSION); } if(!nfc_device_load_data(dev, path, true)) break; restored = true; diff --git a/lib/nfc/nfc_device.h b/lib/nfc/nfc_device.h index 4be07f016..55ee4ac4c 100644 --- a/lib/nfc/nfc_device.h +++ b/lib/nfc/nfc_device.h @@ -20,7 +20,6 @@ extern "C" { #define NFC_READER_DATA_MAX_SIZE 64 #define NFC_DICT_KEY_BATCH_SIZE 50 -#define NFC_APP_FOLDER ANY_PATH("nfc") #define NFC_APP_EXTENSION ".nfc" #define NFC_APP_SHADOW_EXTENSION ".shd" @@ -84,6 +83,7 @@ typedef struct { NfcDeviceData dev_data; char dev_name[NFC_DEV_NAME_MAX_LEN + 1]; FuriString* load_path; + FuriString* folder; NfcDeviceSaveFormat format; bool shadow_file_exist; From 4ed4ea7f4d26712c37dc9577ee4c395948d8eed7 Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Mon, 19 Dec 2022 21:46:36 +0100 Subject: [PATCH 3/6] NFC --- applications/main/nfc/nfc.c | 3 +- applications/main/nfc/nfc_i.h | 1 + applications/plugins/nfc_magic/nfc_magic.c | 3 +- applications/plugins/nfc_magic/nfc_magic_i.h | 2 + fbt_options.py | 2 +- lib/nfc/nfc_device.c | 54 ++++++++++++++++---- lib/nfc/nfc_device.h | 2 +- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/applications/main/nfc/nfc.c b/applications/main/nfc/nfc.c index 76d8f8ef8..115821afd 100644 --- a/applications/main/nfc/nfc.c +++ b/applications/main/nfc/nfc.c @@ -46,7 +46,8 @@ Nfc* nfc_alloc() { // Nfc device nfc->dev = nfc_device_alloc(); - + furi_string_set(nfc->dev->folder, NFC_APP_FOLDER); + // Open GUI record nfc->gui = furi_record_open(RECORD_GUI); diff --git a/applications/main/nfc/nfc_i.h b/applications/main/nfc/nfc_i.h index 339db66c7..a3a62972c 100644 --- a/applications/main/nfc/nfc_i.h +++ b/applications/main/nfc/nfc_i.h @@ -45,6 +45,7 @@ ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST); #define NFC_TEXT_STORE_SIZE 128 +#define NFC_APP_FOLDER ANY_PATH("nfc") typedef enum { NfcRpcStateIdle, diff --git a/applications/plugins/nfc_magic/nfc_magic.c b/applications/plugins/nfc_magic/nfc_magic.c index 38eecba6a..18ffa9a54 100644 --- a/applications/plugins/nfc_magic/nfc_magic.c +++ b/applications/plugins/nfc_magic/nfc_magic.c @@ -49,7 +49,8 @@ NfcMagic* nfc_magic_alloc() { // Nfc device nfc_magic->nfc_dev = nfc_device_alloc(); - + furi_string_set(nfc_magic->nfc_dev->folder, NFC_APP_FOLDER); + // Open GUI record nfc_magic->gui = furi_record_open(RECORD_GUI); view_dispatcher_attach_to_gui( diff --git a/applications/plugins/nfc_magic/nfc_magic_i.h b/applications/plugins/nfc_magic/nfc_magic_i.h index 78f7256ac..a6f9352b4 100644 --- a/applications/plugins/nfc_magic/nfc_magic_i.h +++ b/applications/plugins/nfc_magic/nfc_magic_i.h @@ -27,6 +27,8 @@ #include #include "NFC_Magic_icons.h" +#define NFC_APP_FOLDER ANY_PATH("nfc") + enum NfcMagicCustomEvent { // Reserve first 100 events for button types and indexes, starting from 0 NfcMagicCustomEventReserved = 100, diff --git a/fbt_options.py b/fbt_options.py index 1ec55495e..3279cb05d 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -14,7 +14,7 @@ DEBUG = 0 # Suffix to add to files when building distribution # If OS environment has DIST_SUFFIX set, it will be used instead -DIST_SUFFIX = "CC_CL-0020_12192022" +DIST_SUFFIX = "CC_CL-0021_12192022" # Coprocessor firmware COPRO_OB_DATA = "scripts/ob.data" diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 343181269..2fa9d0b7c 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -27,6 +27,7 @@ NfcDevice* nfc_device_alloc() { nfc_dev->dialogs = furi_record_open(RECORD_DIALOGS); nfc_dev->load_path = furi_string_alloc(); nfc_dev->dev_data.parsed_data = furi_string_alloc(); + nfc_dev->folder = furi_string_alloc(); // Rename cache folder name for backward compatibility if(storage_common_stat(nfc_dev->storage, "/ext/nfc/cache", NULL) == FSE_OK) { @@ -42,6 +43,7 @@ void nfc_device_free(NfcDevice* nfc_dev) { furi_record_close(RECORD_DIALOGS); furi_string_free(nfc_dev->load_path); furi_string_free(nfc_dev->dev_data.parsed_data); + furi_string_free(nfc_dev->folder); free(nfc_dev); } @@ -1328,6 +1330,16 @@ static void nfc_device_get_shadow_path(FuriString* orig_path, FuriString* shadow furi_string_cat_printf(shadow_path, "%s", NFC_APP_SHADOW_EXTENSION); } +static void nfc_device_get_folder_from_path(FuriString* path, FuriString* folder) { + size_t last_slash = furi_string_search_rchar(path, '/'); + if(last_slash == FURI_STRING_FAILURE) { + // No slashes in the path, treat the whole path as a folder + furi_string_set(folder, path); + } else { + furi_string_set_n(folder, path, 0, last_slash); + } +} + bool nfc_device_save(NfcDevice* dev, const char* dev_name) { furi_assert(dev); @@ -1338,10 +1350,19 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { temp_str = furi_string_alloc(); do { - // Create nfc directory if necessary - if(!storage_simply_mkdir(dev->storage, NFC_APP_FOLDER)) break; - // First remove nfc device file if it was saved - furi_string_printf(temp_str, "%s", dev_name); + // Create directory if necessary + FuriString* folder = furi_string_alloc(); + // Get folder from filename (filename is in the form of "folder/filename.nfc", so the folder is "folder/") + furi_string_set(temp_str, dev_name); + // Get folder from filename + nfc_device_get_folder_from_path(temp_str, folder); + FURI_LOG_I("Nfc", "Saving to folder %s", furi_string_get_cstr(folder)); + if(!storage_simply_mkdir(dev->storage, furi_string_get_cstr(folder))) { + FURI_LOG_E("Nfc", "Failed to create folder %s", furi_string_get_cstr(folder)); + break; + } + furi_string_free(folder); + // Open file if(!flipper_format_file_open_always(file, furi_string_get_cstr(temp_str))) break; // Write header @@ -1520,10 +1541,9 @@ bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog) { bool nfc_file_select(NfcDevice* dev) { furi_assert(dev); + const char* folder = furi_string_get_cstr(dev->folder); // Input events and views are managed by file_browser - FuriString* nfc_app_folder; - nfc_app_folder = furi_string_alloc_set(NFC_APP_FOLDER); const DialogsFileBrowserOptions browser_options = { .extension = NFC_APP_EXTENSION, @@ -1533,13 +1553,12 @@ bool nfc_file_select(NfcDevice* dev) { .hide_ext = true, .item_loader_callback = NULL, .item_loader_context = NULL, - .base_path = NFC_APP_FOLDER, + .base_path = folder, }; bool res = dialog_file_browser_show(dev->dialogs, dev->load_path, dev->load_path, &browser_options); - furi_string_free(nfc_app_folder); if(res) { FuriString* filename; filename = furi_string_alloc(); @@ -1601,7 +1620,11 @@ bool nfc_device_delete(NfcDevice* dev, bool use_load_path) { nfc_device_get_shadow_path(dev->load_path, file_path); } else { furi_string_printf( - file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION); + file_path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_SHADOW_EXTENSION); } if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break; } @@ -1630,14 +1653,23 @@ bool nfc_device_restore(NfcDevice* dev, bool use_load_path) { nfc_device_get_shadow_path(dev->load_path, path); } else { furi_string_printf( - path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION); + path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_SHADOW_EXTENSION); } if(!storage_simply_remove(dev->storage, furi_string_get_cstr(path))) break; dev->shadow_file_exist = false; if(use_load_path && !furi_string_empty(dev->load_path)) { furi_string_set(path, dev->load_path); } else { - furi_string_printf(path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION); + furi_string_printf( + path, + "%s/%s%s", + furi_string_get_cstr(dev->folder), + dev->dev_name, + NFC_APP_EXTENSION); } if(!nfc_device_load_data(dev, path, true)) break; restored = true; diff --git a/lib/nfc/nfc_device.h b/lib/nfc/nfc_device.h index 5ad6c4761..c1f95f5b8 100644 --- a/lib/nfc/nfc_device.h +++ b/lib/nfc/nfc_device.h @@ -22,7 +22,6 @@ extern "C" { #define NFC_READER_DATA_MAX_SIZE 64 #define NFC_DICT_KEY_BATCH_SIZE 50 -#define NFC_APP_FOLDER ANY_PATH("nfc") #define NFC_APP_EXTENSION ".nfc" #define NFC_APP_SHADOW_EXTENSION ".shd" @@ -91,6 +90,7 @@ typedef struct { NfcDeviceData dev_data; char dev_name[NFC_DEV_NAME_MAX_LEN + 1]; FuriString* load_path; + FuriString* folder; NfcDeviceSaveFormat format; bool shadow_file_exist; From cea79f66109f896cc1a177cfac197522fd7db103 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Mon, 19 Dec 2022 15:55:36 -0500 Subject: [PATCH 4/6] Update mrtd.h --- lib/nfc/protocols/mrtd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nfc/protocols/mrtd.h b/lib/nfc/protocols/mrtd.h index 94cd0ece6..57bd1d72c 100644 --- a/lib/nfc/protocols/mrtd.h +++ b/lib/nfc/protocols/mrtd.h @@ -3,7 +3,7 @@ #include #include -#define MRTD_APP_FOLDER NFC_APP_FOLDER "/mrtd" +#define MRTD_APP_FOLDER "/mrtd" #define MRTD_APP_EXTENSION ".mrtd" typedef struct { From ccd5a0ffc602f23600b870d7805b3f588af28c32 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Mon, 19 Dec 2022 15:57:13 -0500 Subject: [PATCH 5/6] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bb78df618..4f9be348d 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,4 @@ openocd.log PVS-Studio.log .gdbinit -buildReleasePATREON.sh +PATREONbuildRelease.sh \ No newline at end of file From 6d265d164b728cbb4d59d8ee6458262464125084 Mon Sep 17 00:00:00 2001 From: VerstreuteSeele Date: Mon, 19 Dec 2022 21:58:32 +0100 Subject: [PATCH 6/6] NFC - Part 2 --- lib/nfc/protocols/mrtd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nfc/protocols/mrtd.h b/lib/nfc/protocols/mrtd.h index 94cd0ece6..57bd1d72c 100644 --- a/lib/nfc/protocols/mrtd.h +++ b/lib/nfc/protocols/mrtd.h @@ -3,7 +3,7 @@ #include #include -#define MRTD_APP_FOLDER NFC_APP_FOLDER "/mrtd" +#define MRTD_APP_FOLDER "/mrtd" #define MRTD_APP_EXTENSION ".mrtd" typedef struct {