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
+9 -37
View File
@@ -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;
+1 -1
View File
@@ -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;