This commit is contained in:
VerstreuteSeele
2022-12-19 04:24:49 +01:00
parent 52b4c1ea2f
commit c1a17efea7
10 changed files with 11 additions and 47 deletions

View File

@@ -45,7 +45,6 @@
ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST); ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST);
#define NFC_TEXT_STORE_SIZE 128 #define NFC_TEXT_STORE_SIZE 128
#define NFC_APP_FOLDER ANY_PATH("nfc")
typedef enum { typedef enum {
NfcRpcStateIdle, NfcRpcStateIdle,

View File

@@ -52,7 +52,6 @@ void nfc_scene_delete_on_enter(void* context) {
bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) { bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context; Nfc* nfc = context;
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
bool consumed = false; bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {

View File

@@ -3,7 +3,6 @@
void nfc_scene_file_select_on_enter(void* context) { void nfc_scene_file_select_on_enter(void* context) {
Nfc* nfc = context; Nfc* nfc = context;
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
// Process file_select return // Process file_select return
nfc_device_set_loading_callback(nfc->dev, nfc_show_loading_popup, nfc); nfc_device_set_loading_callback(nfc->dev, nfc_show_loading_popup, nfc);
if(!furi_string_size(nfc->dev->load_path)) { if(!furi_string_size(nfc->dev->load_path)) {

View File

@@ -24,7 +24,6 @@ void nfc_scene_restore_original_confirm_on_enter(void* context) {
bool nfc_scene_restore_original_confirm_on_event(void* context, SceneManagerEvent event) { bool nfc_scene_restore_original_confirm_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context; Nfc* nfc = context;
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
bool consumed = false; bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {

View File

@@ -51,7 +51,6 @@ void nfc_scene_save_name_on_enter(void* context) {
bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) { bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context; Nfc* nfc = context;
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
bool consumed = false; bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {

View File

@@ -27,8 +27,6 @@
#include <lib/nfc/nfc_device.h> #include <lib/nfc/nfc_device.h>
#include "NFC_Magic_icons.h" #include "NFC_Magic_icons.h"
#define NFC_APP_FOLDER ANY_PATH("nfc")
enum NfcMagicCustomEvent { enum NfcMagicCustomEvent {
// Reserve first 100 events for button types and indexes, starting from 0 // Reserve first 100 events for button types and indexes, starting from 0
NfcMagicCustomEventReserved = 100, NfcMagicCustomEventReserved = 100,

View File

@@ -8,7 +8,6 @@ static bool nfc_magic_scene_file_select_is_file_suitable(NfcDevice* nfc_dev) {
void nfc_magic_scene_file_select_on_enter(void* context) { void nfc_magic_scene_file_select_on_enter(void* context) {
NfcMagic* nfc_magic = context; NfcMagic* nfc_magic = context;
furi_string_printf(nfc_magic->nfc_dev->folder, "%s", NFC_APP_FOLDER);
// Process file_select return // Process file_select return
nfc_device_set_loading_callback(nfc_magic->nfc_dev, nfc_magic_show_loading_popup, nfc_magic); nfc_device_set_loading_callback(nfc_magic->nfc_dev, nfc_magic_show_loading_popup, nfc_magic);

View File

@@ -14,7 +14,7 @@ DEBUG = 0
# Suffix to add to files when building distribution # Suffix to add to files when building distribution
# If OS environment has DIST_SUFFIX set, it will be used instead # If OS environment has DIST_SUFFIX set, it will be used instead
DIST_SUFFIX = "CC_CL-0014_12192022" DIST_SUFFIX = "CC_CL-0015_12192022"
# Coprocessor firmware # Coprocessor firmware
COPRO_OB_DATA = "scripts/ob.data" COPRO_OB_DATA = "scripts/ob.data"

View File

@@ -27,7 +27,6 @@ NfcDevice* nfc_device_alloc() {
nfc_dev->dialogs = furi_record_open(RECORD_DIALOGS); nfc_dev->dialogs = furi_record_open(RECORD_DIALOGS);
nfc_dev->load_path = furi_string_alloc(); nfc_dev->load_path = furi_string_alloc();
nfc_dev->dev_data.parsed_data = 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 // Rename cache folder name for backward compatibility
if(storage_common_stat(nfc_dev->storage, "/ext/nfc/cache", NULL) == FSE_OK) { if(storage_common_stat(nfc_dev->storage, "/ext/nfc/cache", NULL) == FSE_OK) {
@@ -43,7 +42,6 @@ void nfc_device_free(NfcDevice* nfc_dev) {
furi_record_close(RECORD_DIALOGS); furi_record_close(RECORD_DIALOGS);
furi_string_free(nfc_dev->load_path); furi_string_free(nfc_dev->load_path);
furi_string_free(nfc_dev->dev_data.parsed_data); furi_string_free(nfc_dev->dev_data.parsed_data);
furi_string_free(nfc_dev->folder);
free(nfc_dev); free(nfc_dev);
} }
@@ -1330,11 +1328,6 @@ static void nfc_device_get_shadow_path(FuriString* orig_path, FuriString* shadow
furi_string_cat_printf(shadow_path, "%s", NFC_APP_SHADOW_EXTENSION); 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, '/');
furi_string_set_n(folder, path, 0, last_slash);
}
bool nfc_device_save(NfcDevice* dev, const char* dev_name) { bool nfc_device_save(NfcDevice* dev, const char* dev_name) {
furi_assert(dev); furi_assert(dev);
@@ -1345,18 +1338,8 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) {
temp_str = furi_string_alloc(); temp_str = furi_string_alloc();
do { do {
// Create directory if necessary // Create nfc directory if necessary
FuriString* folder = furi_string_alloc(); if(!storage_simply_mkdir(dev->storage, NFC_APP_FOLDER)) break;
// Get folder from filename (filename is in the form of "folder/filename.nfc", so the folder is "folder/")
furi_string_printf(temp_str, "%s", 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 // First remove nfc device file if it was saved
furi_string_printf(temp_str, "%s", dev_name); furi_string_printf(temp_str, "%s", dev_name);
// Open file // Open file
@@ -1537,9 +1520,10 @@ bool nfc_device_load(NfcDevice* dev, const char* file_path, bool show_dialog) {
bool nfc_file_select(NfcDevice* dev) { bool nfc_file_select(NfcDevice* dev) {
furi_assert(dev); furi_assert(dev);
const char* folder = furi_string_get_cstr(dev->folder);
// Input events and views are managed by file_browser // 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 = { const DialogsFileBrowserOptions browser_options = {
.extension = NFC_APP_EXTENSION, .extension = NFC_APP_EXTENSION,
@@ -1549,12 +1533,13 @@ bool nfc_file_select(NfcDevice* dev) {
.hide_ext = true, .hide_ext = true,
.item_loader_callback = NULL, .item_loader_callback = NULL,
.item_loader_context = NULL, .item_loader_context = NULL,
.base_path = folder, .base_path = NFC_APP_FOLDER,
}; };
bool res = bool res =
dialog_file_browser_show(dev->dialogs, dev->load_path, dev->load_path, &browser_options); dialog_file_browser_show(dev->dialogs, dev->load_path, dev->load_path, &browser_options);
furi_string_free(nfc_app_folder);
if(res) { if(res) {
FuriString* filename; FuriString* filename;
filename = furi_string_alloc(); filename = furi_string_alloc();
@@ -1607,11 +1592,7 @@ bool nfc_device_delete(NfcDevice* dev, bool use_load_path) {
furi_string_set(file_path, dev->load_path); furi_string_set(file_path, dev->load_path);
} else { } else {
furi_string_printf( furi_string_printf(
file_path, file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION);
"%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; if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break;
// Delete shadow file if it exists // Delete shadow file if it exists
@@ -1620,11 +1601,7 @@ bool nfc_device_delete(NfcDevice* dev, bool use_load_path) {
nfc_device_get_shadow_path(dev->load_path, file_path); nfc_device_get_shadow_path(dev->load_path, file_path);
} else { } else {
furi_string_printf( furi_string_printf(
file_path, file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION);
"%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; if(!storage_simply_remove(dev->storage, furi_string_get_cstr(file_path))) break;
} }
@@ -1660,12 +1637,7 @@ bool nfc_device_restore(NfcDevice* dev, bool use_load_path) {
if(use_load_path && !furi_string_empty(dev->load_path)) { if(use_load_path && !furi_string_empty(dev->load_path)) {
furi_string_set(path, dev->load_path); furi_string_set(path, dev->load_path);
} else { } else {
furi_string_printf( furi_string_printf(path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION);
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; if(!nfc_device_load_data(dev, path, true)) break;
restored = true; restored = true;

View File

@@ -22,6 +22,7 @@ extern "C" {
#define NFC_READER_DATA_MAX_SIZE 64 #define NFC_READER_DATA_MAX_SIZE 64
#define NFC_DICT_KEY_BATCH_SIZE 50 #define NFC_DICT_KEY_BATCH_SIZE 50
#define NFC_APP_FOLDER ANY_PATH("nfc")
#define NFC_APP_EXTENSION ".nfc" #define NFC_APP_EXTENSION ".nfc"
#define NFC_APP_SHADOW_EXTENSION ".shd" #define NFC_APP_SHADOW_EXTENSION ".shd"
@@ -90,7 +91,6 @@ typedef struct {
NfcDeviceData dev_data; NfcDeviceData dev_data;
char dev_name[NFC_DEV_NAME_MAX_LEN + 1]; char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
FuriString* load_path; FuriString* load_path;
FuriString* folder;
NfcDeviceSaveFormat format; NfcDeviceSaveFormat format;
bool shadow_file_exist; bool shadow_file_exist;