mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 11:48:35 -07:00
NFC Fix
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST);
|
||||
|
||||
#define NFC_TEXT_STORE_SIZE 128
|
||||
#define NFC_APP_FOLDER ANY_PATH("nfc")
|
||||
|
||||
typedef enum {
|
||||
NfcRpcStateIdle,
|
||||
|
||||
@@ -52,7 +52,6 @@ void nfc_scene_delete_on_enter(void* context) {
|
||||
|
||||
bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
void nfc_scene_file_select_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
|
||||
// Process file_select return
|
||||
nfc_device_set_loading_callback(nfc->dev, nfc_show_loading_popup, nfc);
|
||||
if(!furi_string_size(nfc->dev->load_path)) {
|
||||
|
||||
@@ -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) {
|
||||
Nfc* nfc = context;
|
||||
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
|
||||
@@ -51,7 +51,6 @@ void nfc_scene_save_name_on_enter(void* context) {
|
||||
|
||||
bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
furi_string_printf(nfc->dev->folder, "%s", NFC_APP_FOLDER);
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <lib/nfc/nfc_device.h>
|
||||
#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,
|
||||
|
||||
@@ -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) {
|
||||
NfcMagic* nfc_magic = context;
|
||||
furi_string_printf(nfc_magic->nfc_dev->folder, "%s", NFC_APP_FOLDER);
|
||||
// Process file_select return
|
||||
nfc_device_set_loading_callback(nfc_magic->nfc_dev, nfc_magic_show_loading_popup, nfc_magic);
|
||||
|
||||
|
||||
@@ -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-0014_12192022"
|
||||
DIST_SUFFIX = "CC_CL-0015_12192022"
|
||||
|
||||
# Coprocessor firmware
|
||||
COPRO_OB_DATA = "scripts/ob.data"
|
||||
|
||||
@@ -27,7 +27,6 @@ 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) {
|
||||
@@ -43,7 +42,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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) {
|
||||
furi_assert(dev);
|
||||
|
||||
@@ -1345,18 +1338,8 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) {
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
do {
|
||||
// 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_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);
|
||||
// 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);
|
||||
// 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) {
|
||||
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,
|
||||
@@ -1549,12 +1533,13 @@ bool nfc_file_select(NfcDevice* dev) {
|
||||
.hide_ext = true,
|
||||
.item_loader_callback = NULL,
|
||||
.item_loader_context = NULL,
|
||||
.base_path = folder,
|
||||
.base_path = NFC_APP_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();
|
||||
@@ -1607,11 +1592,7 @@ 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",
|
||||
furi_string_get_cstr(dev->folder),
|
||||
dev->dev_name,
|
||||
NFC_APP_EXTENSION);
|
||||
file_path, "%s/%s%s", NFC_APP_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
|
||||
@@ -1620,11 +1601,7 @@ 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",
|
||||
furi_string_get_cstr(dev->folder),
|
||||
dev->dev_name,
|
||||
NFC_APP_SHADOW_EXTENSION);
|
||||
file_path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_SHADOW_EXTENSION);
|
||||
}
|
||||
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)) {
|
||||
furi_string_set(path, dev->load_path);
|
||||
} else {
|
||||
furi_string_printf(
|
||||
path,
|
||||
"%s/%s%s",
|
||||
furi_string_get_cstr(dev->folder),
|
||||
dev->dev_name,
|
||||
NFC_APP_EXTENSION);
|
||||
furi_string_printf(path, "%s/%s%s", NFC_APP_FOLDER, dev->dev_name, NFC_APP_EXTENSION);
|
||||
}
|
||||
if(!nfc_device_load_data(dev, path, true)) break;
|
||||
restored = true;
|
||||
|
||||
@@ -22,6 +22,7 @@ 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"
|
||||
|
||||
@@ -90,7 +91,6 @@ 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user