[FL-2274] Inventing streams and moving FFF to them (#981)
* Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include "scene/lfrfid_app_scene_delete_success.h"
|
||||
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_file/flipper_file.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
const char* LfRfidApp::app_folder = "/any/lfrfid";
|
||||
const char* LfRfidApp::app_extension = ".rfid";
|
||||
@@ -119,17 +119,17 @@ bool LfRfidApp::delete_key(RfidKey* key) {
|
||||
}
|
||||
|
||||
bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
|
||||
FlipperFile* file = flipper_file_alloc(storage);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
bool result = false;
|
||||
string_t str_result;
|
||||
string_init(str_result);
|
||||
|
||||
do {
|
||||
if(!flipper_file_open_existing(file, path)) break;
|
||||
if(!flipper_format_file_open_existing(file, path)) break;
|
||||
|
||||
// header
|
||||
uint32_t version;
|
||||
if(!flipper_file_read_header(file, str_result, &version)) break;
|
||||
if(!flipper_format_read_header(file, str_result, &version)) break;
|
||||
if(string_cmp_str(str_result, app_filetype) != 0) break;
|
||||
if(version != 1) break;
|
||||
|
||||
@@ -137,13 +137,14 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
|
||||
LfrfidKeyType type;
|
||||
RfidKey loaded_key;
|
||||
|
||||
if(!flipper_file_read_string(file, "Key type", str_result)) break;
|
||||
if(!flipper_format_read_string(file, "Key type", str_result)) break;
|
||||
if(!lfrfid_key_get_string_type(string_get_cstr(str_result), &type)) break;
|
||||
loaded_key.set_type(type);
|
||||
|
||||
// key data
|
||||
uint8_t key_data[loaded_key.get_type_data_count()] = {};
|
||||
if(!flipper_file_read_hex(file, "Data", key_data, loaded_key.get_type_data_count())) break;
|
||||
if(!flipper_format_read_hex(file, "Data", key_data, loaded_key.get_type_data_count()))
|
||||
break;
|
||||
loaded_key.set_data(key_data, loaded_key.get_type_data_count());
|
||||
|
||||
path_extract_filename_no_ext(path, str_result);
|
||||
@@ -153,8 +154,7 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
|
||||
result = true;
|
||||
} while(0);
|
||||
|
||||
flipper_file_close(file);
|
||||
flipper_file_free(file);
|
||||
flipper_format_free(file);
|
||||
string_clear(str_result);
|
||||
|
||||
if(!result) {
|
||||
@@ -165,27 +165,26 @@ bool LfRfidApp::load_key_data(const char* path, RfidKey* key) {
|
||||
}
|
||||
|
||||
bool LfRfidApp::save_key_data(const char* path, RfidKey* key) {
|
||||
FlipperFile* file = flipper_file_alloc(storage);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
bool result = false;
|
||||
|
||||
do {
|
||||
if(!flipper_file_open_always(file, path)) break;
|
||||
if(!flipper_file_write_header_cstr(file, app_filetype, 1)) break;
|
||||
if(!flipper_file_write_comment_cstr(file, "Key type can be EM4100, H10301 or I40134"))
|
||||
if(!flipper_format_file_open_always(file, path)) break;
|
||||
if(!flipper_format_write_header_cstr(file, app_filetype, 1)) break;
|
||||
if(!flipper_format_write_comment_cstr(file, "Key type can be EM4100, H10301 or I40134"))
|
||||
break;
|
||||
if(!flipper_file_write_string_cstr(
|
||||
if(!flipper_format_write_string_cstr(
|
||||
file, "Key type", lfrfid_key_get_type_string(key->get_type())))
|
||||
break;
|
||||
if(!flipper_file_write_comment_cstr(
|
||||
if(!flipper_format_write_comment_cstr(
|
||||
file, "Data size for EM4100 is 5, for H10301 is 3, for I40134 is 3"))
|
||||
break;
|
||||
if(!flipper_file_write_hex(file, "Data", key->get_data(), key->get_type_data_count()))
|
||||
if(!flipper_format_write_hex(file, "Data", key->get_data(), key->get_type_data_count()))
|
||||
break;
|
||||
result = true;
|
||||
} while(0);
|
||||
|
||||
flipper_file_close(file);
|
||||
flipper_file_free(file);
|
||||
flipper_format_free(file);
|
||||
|
||||
if(!result) {
|
||||
dialog_message_show_storage_error(dialogs, "Cannot save\nkey file");
|
||||
|
Reference in New Issue
Block a user