[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:
@@ -3,7 +3,7 @@
|
||||
#include <callback-connector.h>
|
||||
#include <m-string.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_file/flipper_file.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
const char* iButtonApp::app_folder = "/any/ibutton";
|
||||
const char* iButtonApp::app_extension = ".ibtn";
|
||||
@@ -191,7 +191,7 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
// Create ibutton directory if necessary
|
||||
make_app_folder();
|
||||
|
||||
FlipperFile* file = flipper_file_alloc(storage);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
string_t key_file_name;
|
||||
bool result = false;
|
||||
string_init(key_file_name);
|
||||
@@ -207,29 +207,29 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
string_printf(key_file_name, "%s/%s%s", app_folder, key.get_name(), app_extension);
|
||||
|
||||
// Open file for write
|
||||
if(!flipper_file_open_always(file, string_get_cstr(key_file_name))) break;
|
||||
if(!flipper_format_file_open_always(file, string_get_cstr(key_file_name))) break;
|
||||
|
||||
// Write header
|
||||
if(!flipper_file_write_header_cstr(file, iButtonApp::app_filetype, 1)) break;
|
||||
if(!flipper_format_write_header_cstr(file, iButtonApp::app_filetype, 1)) break;
|
||||
|
||||
// Write key type
|
||||
if(!flipper_file_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
|
||||
if(!flipper_format_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
|
||||
break;
|
||||
const char* key_type = key.get_key_type_string_by_type(key.get_key_type());
|
||||
if(!flipper_file_write_string_cstr(file, "Key type", key_type)) break;
|
||||
if(!flipper_format_write_string_cstr(file, "Key type", key_type)) break;
|
||||
|
||||
// Write data
|
||||
if(!flipper_file_write_comment_cstr(
|
||||
if(!flipper_format_write_comment_cstr(
|
||||
file, "Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8"))
|
||||
break;
|
||||
|
||||
if(!flipper_file_write_hex(file, "Data", key.get_data(), key.get_type_data_size())) break;
|
||||
if(!flipper_format_write_hex(file, "Data", key.get_data(), key.get_type_data_size()))
|
||||
break;
|
||||
result = true;
|
||||
|
||||
} while(false);
|
||||
|
||||
flipper_file_close(file);
|
||||
flipper_file_free(file);
|
||||
flipper_format_free(file);
|
||||
|
||||
string_clear(key_file_name);
|
||||
|
||||
@@ -241,28 +241,28 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
}
|
||||
|
||||
bool iButtonApp::load_key_data(string_t key_path) {
|
||||
FlipperFile* file = flipper_file_alloc(storage);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
bool result = false;
|
||||
string_t data;
|
||||
string_init(data);
|
||||
|
||||
do {
|
||||
if(!flipper_file_open_existing(file, string_get_cstr(key_path))) break;
|
||||
if(!flipper_format_file_open_existing(file, string_get_cstr(key_path))) break;
|
||||
|
||||
// header
|
||||
uint32_t version;
|
||||
if(!flipper_file_read_header(file, data, &version)) break;
|
||||
if(!flipper_format_read_header(file, data, &version)) break;
|
||||
if(string_cmp_str(data, iButtonApp::app_filetype) != 0) break;
|
||||
if(version != 1) break;
|
||||
|
||||
// key type
|
||||
iButtonKeyType type;
|
||||
if(!flipper_file_read_string(file, "Key type", data)) break;
|
||||
if(!flipper_format_read_string(file, "Key type", data)) break;
|
||||
if(!key.get_key_type_by_type_string(string_get_cstr(data), &type)) break;
|
||||
|
||||
// key data
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
|
||||
if(!flipper_file_read_hex(file, "Data", key_data, key.get_type_data_size_by_type(type)))
|
||||
if(!flipper_format_read_hex(file, "Data", key_data, key.get_type_data_size_by_type(type)))
|
||||
break;
|
||||
|
||||
key.set_type(type);
|
||||
@@ -271,8 +271,7 @@ bool iButtonApp::load_key_data(string_t key_path) {
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
flipper_file_close(file);
|
||||
flipper_file_free(file);
|
||||
flipper_format_free(file);
|
||||
string_clear(data);
|
||||
|
||||
if(!result) {
|
||||
|
Reference in New Issue
Block a user