M*LIB: non-inlined strings, FuriString primitive (#1795)

* Quicksave 1
* Header stage complete
* Source stage complete
* Lint & merge fixes
* Includes
* Documentation step 1
* FBT: output free size considering BT STACK
* Documentation step 2
* py lint
* Fix music player plugin
* unit test stage 1: string allocator, mem, getters, setters, appends, compare, search.
* unit test: string equality
* unit test: string replace
* unit test: string start_with, end_with
* unit test: string trim
* unit test: utf-8
* Rename
* Revert fw_size changes
* Simplify CLI backspace handling
* Simplify CLI character insert
* Merge fixes
* Furi: correct filenaming and spelling
* Bt: remove furi string include

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Sergey Gavrilov
2022-10-06 01:15:23 +10:00
committed by GitHub
parent 0f9ea925d3
commit 4bf29827f8
370 changed files with 5597 additions and 3963 deletions

View File

@@ -11,8 +11,8 @@
#define LFS_BACKUP_DEFAULT_LOCATION EXT_PATH(LFS_BACKUP_DEFAULT_FILENAME)
static void backup_name_converter(string_t filename) {
if(string_empty_p(filename) || (string_get_char(filename, 0) == '.')) {
static void backup_name_converter(FuriString* filename) {
if(furi_string_empty(filename) || (furi_string_get_char(filename, 0) == '.')) {
return;
}
@@ -27,8 +27,8 @@ static void backup_name_converter(string_t filename) {
};
for(size_t i = 0; i < COUNT_OF(names); i++) {
if(string_equal_str_p(filename, &names[i][1])) {
string_set_str(filename, names[i]);
if(furi_string_equal(filename, &names[i][1])) {
furi_string_set(filename, names[i]);
return;
}
}

View File

@@ -6,7 +6,7 @@
struct ResourceManifestReader {
Storage* storage;
Stream* stream;
string_t linebuf;
FuriString* linebuf;
ResourceManifestEntry entry;
};
@@ -16,16 +16,16 @@ ResourceManifestReader* resource_manifest_reader_alloc(Storage* storage) {
resource_manifest->storage = storage;
resource_manifest->stream = buffered_file_stream_alloc(resource_manifest->storage);
memset(&resource_manifest->entry, 0, sizeof(ResourceManifestEntry));
string_init(resource_manifest->entry.name);
string_init(resource_manifest->linebuf);
resource_manifest->entry.name = furi_string_alloc();
resource_manifest->linebuf = furi_string_alloc();
return resource_manifest;
}
void resource_manifest_reader_free(ResourceManifestReader* resource_manifest) {
furi_assert(resource_manifest);
string_clear(resource_manifest->linebuf);
string_clear(resource_manifest->entry.name);
furi_string_free(resource_manifest->linebuf);
furi_string_free(resource_manifest->entry.name);
buffered_file_stream_close(resource_manifest->stream);
stream_free(resource_manifest->stream);
free(resource_manifest);
@@ -45,7 +45,7 @@ bool resource_manifest_reader_open(ResourceManifestReader* resource_manifest, co
ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* resource_manifest) {
furi_assert(resource_manifest);
string_reset(resource_manifest->entry.name);
furi_string_reset(resource_manifest->entry.name);
resource_manifest->entry.type = ResourceManifestEntryTypeUnknown;
resource_manifest->entry.size = 0;
memset(resource_manifest->entry.hash, 0, sizeof(resource_manifest->entry.hash));
@@ -56,9 +56,9 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
}
/* Trim end of line */
string_strim(resource_manifest->linebuf);
furi_string_trim(resource_manifest->linebuf);
char type_code = string_get_char(resource_manifest->linebuf, 0);
char type_code = furi_string_get_char(resource_manifest->linebuf, 0);
switch(type_code) {
case 'F':
resource_manifest->entry.type = ResourceManifestEntryTypeFile;
@@ -75,9 +75,9 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
F:<hash>:<size>:<name> */
/* Remove entry type code */
string_right(resource_manifest->linebuf, 2);
furi_string_right(resource_manifest->linebuf, 2);
if(string_search_char(resource_manifest->linebuf, ':') !=
if(furi_string_search_char(resource_manifest->linebuf, ':') !=
sizeof(resource_manifest->entry.hash) * 2) {
/* Invalid hash */
continue;
@@ -85,27 +85,27 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
/* Read hash */
hex_chars_to_uint8(
string_get_cstr(resource_manifest->linebuf), resource_manifest->entry.hash);
furi_string_get_cstr(resource_manifest->linebuf), resource_manifest->entry.hash);
/* Remove hash */
string_right(
furi_string_right(
resource_manifest->linebuf, sizeof(resource_manifest->entry.hash) * 2 + 1);
resource_manifest->entry.size = atoi(string_get_cstr(resource_manifest->linebuf));
resource_manifest->entry.size = atoi(furi_string_get_cstr(resource_manifest->linebuf));
/* Remove size */
size_t offs = string_search_char(resource_manifest->linebuf, ':');
string_right(resource_manifest->linebuf, offs + 1);
size_t offs = furi_string_search_char(resource_manifest->linebuf, ':');
furi_string_right(resource_manifest->linebuf, offs + 1);
string_set(resource_manifest->entry.name, resource_manifest->linebuf);
furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf);
} else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) {
/* Parse directory entry
D:<name> */
/* Remove entry type code */
string_right(resource_manifest->linebuf, 2);
furi_string_right(resource_manifest->linebuf, 2);
string_set(resource_manifest->entry.name, resource_manifest->linebuf);
furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf);
}
return &resource_manifest->entry;

View File

@@ -2,7 +2,6 @@
#include <storage/storage.h>
#include <m-string.h>
#include <stdbool.h>
#include <stdint.h>
@@ -18,7 +17,7 @@ typedef enum {
typedef struct {
ResourceManifestEntryType type;
string_t name;
FuriString* name;
uint32_t size;
uint8_t hash[16];
} ResourceManifestEntry;

View File

@@ -21,12 +21,12 @@
UpdateManifest* update_manifest_alloc() {
UpdateManifest* update_manifest = malloc(sizeof(UpdateManifest));
string_init(update_manifest->version);
string_init(update_manifest->firmware_dfu_image);
string_init(update_manifest->radio_image);
string_init(update_manifest->staged_loader_file);
string_init(update_manifest->resource_bundle);
string_init(update_manifest->splash_file);
update_manifest->version = furi_string_alloc();
update_manifest->firmware_dfu_image = furi_string_alloc();
update_manifest->radio_image = furi_string_alloc();
update_manifest->staged_loader_file = furi_string_alloc();
update_manifest->resource_bundle = furi_string_alloc();
update_manifest->splash_file = furi_string_alloc();
update_manifest->target = 0;
update_manifest->manifest_version = 0;
memset(update_manifest->ob_reference.bytes, 0, FURI_HAL_FLASH_OB_RAW_SIZE_BYTES);
@@ -38,12 +38,12 @@ UpdateManifest* update_manifest_alloc() {
void update_manifest_free(UpdateManifest* update_manifest) {
furi_assert(update_manifest);
string_clear(update_manifest->version);
string_clear(update_manifest->firmware_dfu_image);
string_clear(update_manifest->radio_image);
string_clear(update_manifest->staged_loader_file);
string_clear(update_manifest->resource_bundle);
string_clear(update_manifest->splash_file);
furi_string_free(update_manifest->version);
furi_string_free(update_manifest->firmware_dfu_image);
furi_string_free(update_manifest->radio_image);
furi_string_free(update_manifest->staged_loader_file);
furi_string_free(update_manifest->resource_bundle);
furi_string_free(update_manifest->splash_file);
free(update_manifest);
}
@@ -52,10 +52,10 @@ static bool
furi_assert(update_manifest);
furi_assert(flipper_file);
string_t filetype;
FuriString* filetype;
// TODO: compare filetype?
string_init(filetype);
filetype = furi_string_alloc();
update_manifest->valid =
flipper_format_read_header(flipper_file, filetype, &update_manifest->manifest_version) &&
flipper_format_read_string(flipper_file, MANIFEST_KEY_INFO, update_manifest->version) &&
@@ -68,7 +68,7 @@ static bool
MANIFEST_KEY_LOADER_CRC,
(uint8_t*)&update_manifest->staged_loader_crc,
sizeof(uint32_t));
string_clear(filetype);
furi_string_free(filetype);
if(update_manifest->valid) {
/* Optional fields - we can have dfu, radio, resources, or any combination */
@@ -114,9 +114,9 @@ static bool
flipper_file, MANIFEST_KEY_SPLASH_FILE, update_manifest->splash_file);
update_manifest->valid =
(!string_empty_p(update_manifest->firmware_dfu_image) ||
!string_empty_p(update_manifest->radio_image) ||
!string_empty_p(update_manifest->resource_bundle));
(!furi_string_empty(update_manifest->firmware_dfu_image) ||
!furi_string_empty(update_manifest->radio_image) ||
!furi_string_empty(update_manifest->resource_bundle));
}
return update_manifest->valid;

View File

@@ -6,7 +6,7 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>
#include <m-string.h>
#include <furi.h>
#include <furi_hal_flash.h>
/* Paths don't include /ext -- because at startup SD card is mounted as FS root */
@@ -28,20 +28,20 @@ _Static_assert(sizeof(UpdateManifestRadioVersion) == 6, "UpdateManifestRadioVers
typedef struct {
uint32_t manifest_version;
string_t version;
FuriString* version;
uint32_t target;
string_t staged_loader_file;
FuriString* staged_loader_file;
uint32_t staged_loader_crc;
string_t firmware_dfu_image;
string_t radio_image;
FuriString* firmware_dfu_image;
FuriString* radio_image;
uint32_t radio_address;
UpdateManifestRadioVersion radio_version;
uint32_t radio_crc;
string_t resource_bundle;
FuriString* resource_bundle;
FuriHalFlashRawOptionByteData ob_reference;
FuriHalFlashRawOptionByteData ob_compare_mask;
FuriHalFlashRawOptionByteData ob_write_mask;
string_t splash_file;
FuriString* splash_file;
bool valid;
} UpdateManifest;

View File

@@ -4,7 +4,6 @@
#include <furi.h>
#include <furi_hal.h>
#include <m-string.h>
#include <loader/loader.h>
#include <lib/toolbox/path.h>
#include <lib/toolbox/crc32_calc.h>
@@ -34,9 +33,9 @@ const char* update_operation_describe_preparation_result(const UpdatePrepareResu
}
}
static bool update_operation_get_current_package_path_rtc(Storage* storage, string_t out_path) {
static bool update_operation_get_current_package_path_rtc(Storage* storage, FuriString* out_path) {
const uint32_t update_index = furi_hal_rtc_get_register(FuriHalRtcRegisterUpdateFolderFSIndex);
string_set_str(out_path, UPDATE_ROOT_DIR);
furi_string_set(out_path, UPDATE_ROOT_DIR);
if(update_index == UPDATE_OPERATION_ROOT_DIR_PACKAGE_MAGIC) {
return true;
}
@@ -63,7 +62,7 @@ static bool update_operation_get_current_package_path_rtc(Storage* storage, stri
free(name_buffer);
storage_file_free(dir);
if(!found) {
string_reset(out_path);
furi_string_reset(out_path);
}
return found;
@@ -72,8 +71,8 @@ static bool update_operation_get_current_package_path_rtc(Storage* storage, stri
#define UPDATE_FILE_POINTER_FN EXT_PATH(UPDATE_MANIFEST_POINTER_FILE_NAME)
#define UPDATE_MANIFEST_MAX_PATH_LEN 256u
bool update_operation_get_current_package_manifest_path(Storage* storage, string_t out_path) {
string_reset(out_path);
bool update_operation_get_current_package_manifest_path(Storage* storage, FuriString* out_path) {
furi_string_reset(out_path);
if(storage_common_stat(storage, UPDATE_FILE_POINTER_FN, NULL) == FSE_OK) {
char* manifest_name_buffer = malloc(UPDATE_MANIFEST_MAX_PATH_LEN);
File* upd_file = NULL;
@@ -91,23 +90,23 @@ bool update_operation_get_current_package_manifest_path(Storage* storage, string
if(storage_common_stat(storage, manifest_name_buffer, NULL) != FSE_OK) {
break;
}
string_set_str(out_path, manifest_name_buffer);
furi_string_set(out_path, manifest_name_buffer);
} while(0);
free(manifest_name_buffer);
storage_file_free(upd_file);
} else {
/* legacy, will be deprecated */
string_t rtcpath;
string_init(rtcpath);
FuriString* rtcpath;
rtcpath = furi_string_alloc();
do {
if(!update_operation_get_current_package_path_rtc(storage, rtcpath)) {
break;
}
path_concat(string_get_cstr(rtcpath), UPDATE_MANIFEST_DEFAULT_NAME, out_path);
path_concat(furi_string_get_cstr(rtcpath), UPDATE_MANIFEST_DEFAULT_NAME, out_path);
} while(0);
string_clear(rtcpath);
furi_string_free(rtcpath);
}
return !string_empty_p(out_path);
return !furi_string_empty(out_path);
}
static bool update_operation_persist_manifest_path(Storage* storage, const char* manifest_path) {
@@ -141,8 +140,8 @@ UpdatePrepareResult update_operation_prepare(const char* manifest_file_path) {
File* file = storage_file_alloc(storage);
uint64_t free_int_space;
string_t stage_path;
string_init(stage_path);
FuriString* stage_path;
stage_path = furi_string_alloc();
do {
if((storage_common_fs_info(storage, STORAGE_INT_PATH_PREFIX, NULL, &free_int_space) !=
FSE_OK) ||
@@ -171,9 +170,10 @@ UpdatePrepareResult update_operation_prepare(const char* manifest_file_path) {
}
path_extract_dirname(manifest_file_path, stage_path);
path_append(stage_path, string_get_cstr(manifest->staged_loader_file));
path_append(stage_path, furi_string_get_cstr(manifest->staged_loader_file));
if(!storage_file_open(file, string_get_cstr(stage_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
if(!storage_file_open(
file, furi_string_get_cstr(stage_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
result = UpdatePrepareResultStageMissing;
break;
}
@@ -193,7 +193,7 @@ UpdatePrepareResult update_operation_prepare(const char* manifest_file_path) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePreUpdate);
} while(false);
string_clear(stage_path);
furi_string_free(stage_path);
storage_file_free(file);
update_manifest_free(manifest);

View File

@@ -1,7 +1,6 @@
#pragma once
#include <stdbool.h>
#include <m-string.h>
#include <storage/storage.h>
#ifdef __cplusplus
@@ -19,7 +18,7 @@ extern "C" {
* May be empty if update is in root update directory
* @return bool if supplied path is valid and out_manifest_dir contains dir to apply
*/
bool update_operation_get_package_dir_name(const char* full_path, string_t out_manifest_dir);
bool update_operation_get_package_dir_name(const char* full_path, FuriString* out_manifest_dir);
/* When updating this enum, also update assets/protobuf/system.proto */
typedef enum {
@@ -51,7 +50,7 @@ UpdatePrepareResult update_operation_prepare(const char* manifest_file_path);
* @param out_path Path to manifest. Must be initialized
* @return true if path was restored successfully
*/
bool update_operation_get_current_package_manifest_path(Storage* storage, string_t out_path);
bool update_operation_get_current_package_manifest_path(Storage* storage, FuriString* out_path);
/*
* Checks if an update operation step is pending after reset