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:
@@ -69,19 +69,19 @@ static const UpdateTaskStageGroupMap update_task_stage_progress[] = {
|
||||
static UpdateTaskStageGroup update_task_get_task_groups(UpdateTask* update_task) {
|
||||
UpdateTaskStageGroup ret = UpdateTaskStageGroupPreUpdate | UpdateTaskStageGroupPostUpdate;
|
||||
UpdateManifest* manifest = update_task->manifest;
|
||||
if(!string_empty_p(manifest->radio_image)) {
|
||||
if(!furi_string_empty(manifest->radio_image)) {
|
||||
ret |= UpdateTaskStageGroupRadio;
|
||||
}
|
||||
if(update_manifest_has_obdata(manifest)) {
|
||||
ret |= UpdateTaskStageGroupOptionBytes;
|
||||
}
|
||||
if(!string_empty_p(manifest->firmware_dfu_image)) {
|
||||
if(!furi_string_empty(manifest->firmware_dfu_image)) {
|
||||
ret |= UpdateTaskStageGroupFirmware;
|
||||
}
|
||||
if(!string_empty_p(manifest->resource_bundle)) {
|
||||
if(!furi_string_empty(manifest->resource_bundle)) {
|
||||
ret |= UpdateTaskStageGroupResources;
|
||||
}
|
||||
if(!string_empty_p(manifest->splash_file)) {
|
||||
if(!furi_string_empty(manifest->splash_file)) {
|
||||
ret |= UpdateTaskStageGroupSplashscreen;
|
||||
}
|
||||
return ret;
|
||||
@@ -109,14 +109,14 @@ void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, ui
|
||||
}
|
||||
/* Build error message with code "[stage_idx-stage_percent]" */
|
||||
if(stage >= UpdateTaskStageError) {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
update_task->state.status,
|
||||
"%s #[%d-%d]",
|
||||
update_task_stage_descr[stage],
|
||||
update_task->state.stage,
|
||||
update_task->state.stage_progress);
|
||||
} else {
|
||||
string_set_str(update_task->state.status, update_task_stage_descr[stage]);
|
||||
furi_string_set(update_task->state.status, update_task_stage_descr[stage]);
|
||||
}
|
||||
/* Store stage update */
|
||||
update_task->state.stage = stage;
|
||||
@@ -149,7 +149,7 @@ void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, ui
|
||||
|
||||
if(update_task->status_change_cb) {
|
||||
(update_task->status_change_cb)(
|
||||
string_get_cstr(update_task->state.status),
|
||||
furi_string_get_cstr(update_task->state.status),
|
||||
adapted_progress,
|
||||
update_stage_is_error(update_task->state.stage),
|
||||
update_task->status_change_cb_state);
|
||||
@@ -165,26 +165,26 @@ static void update_task_close_file(UpdateTask* update_task) {
|
||||
storage_file_close(update_task->file);
|
||||
}
|
||||
|
||||
static bool update_task_check_file_exists(UpdateTask* update_task, string_t filename) {
|
||||
static bool update_task_check_file_exists(UpdateTask* update_task, FuriString* filename) {
|
||||
furi_assert(update_task);
|
||||
string_t tmp_path;
|
||||
string_init_set(tmp_path, update_task->update_path);
|
||||
path_append(tmp_path, string_get_cstr(filename));
|
||||
bool exists = storage_file_exists(update_task->storage, string_get_cstr(tmp_path));
|
||||
string_clear(tmp_path);
|
||||
FuriString* tmp_path;
|
||||
tmp_path = furi_string_alloc_set(update_task->update_path);
|
||||
path_append(tmp_path, furi_string_get_cstr(filename));
|
||||
bool exists = storage_file_exists(update_task->storage, furi_string_get_cstr(tmp_path));
|
||||
furi_string_free(tmp_path);
|
||||
return exists;
|
||||
}
|
||||
|
||||
bool update_task_open_file(UpdateTask* update_task, string_t filename) {
|
||||
bool update_task_open_file(UpdateTask* update_task, FuriString* filename) {
|
||||
furi_assert(update_task);
|
||||
update_task_close_file(update_task);
|
||||
|
||||
string_t tmp_path;
|
||||
string_init_set(tmp_path, update_task->update_path);
|
||||
path_append(tmp_path, string_get_cstr(filename));
|
||||
FuriString* tmp_path;
|
||||
tmp_path = furi_string_alloc_set(update_task->update_path);
|
||||
path_append(tmp_path, furi_string_get_cstr(filename));
|
||||
bool open_success = storage_file_open(
|
||||
update_task->file, string_get_cstr(tmp_path), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
string_clear(tmp_path);
|
||||
update_task->file, furi_string_get_cstr(tmp_path), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
furi_string_free(tmp_path);
|
||||
return open_success;
|
||||
}
|
||||
|
||||
@@ -207,14 +207,14 @@ UpdateTask* update_task_alloc() {
|
||||
update_task->state.stage = UpdateTaskStageProgress;
|
||||
update_task->state.stage_progress = 0;
|
||||
update_task->state.overall_progress = 0;
|
||||
string_init(update_task->state.status);
|
||||
update_task->state.status = furi_string_alloc();
|
||||
|
||||
update_task->manifest = update_manifest_alloc();
|
||||
update_task->storage = furi_record_open(RECORD_STORAGE);
|
||||
update_task->file = storage_file_alloc(update_task->storage);
|
||||
update_task->status_change_cb = NULL;
|
||||
update_task->boot_mode = furi_hal_rtc_get_boot_mode();
|
||||
string_init(update_task->update_path);
|
||||
update_task->update_path = furi_string_alloc();
|
||||
|
||||
FuriThread* thread = update_task->thread = furi_thread_alloc();
|
||||
|
||||
@@ -246,7 +246,7 @@ void update_task_free(UpdateTask* update_task) {
|
||||
update_manifest_free(update_task->manifest);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
string_clear(update_task->update_path);
|
||||
furi_string_free(update_task->update_path);
|
||||
|
||||
free(update_task);
|
||||
}
|
||||
@@ -261,8 +261,8 @@ bool update_task_parse_manifest(UpdateTask* update_task) {
|
||||
|
||||
update_task_set_progress(update_task, UpdateTaskStageReadManifest, 0);
|
||||
bool result = false;
|
||||
string_t manifest_path;
|
||||
string_init(manifest_path);
|
||||
FuriString* manifest_path;
|
||||
manifest_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
update_task_set_progress(update_task, UpdateTaskStageProgress, 13);
|
||||
@@ -276,11 +276,11 @@ bool update_task_parse_manifest(UpdateTask* update_task) {
|
||||
break;
|
||||
}
|
||||
|
||||
path_extract_dirname(string_get_cstr(manifest_path), update_task->update_path);
|
||||
path_extract_dirname(furi_string_get_cstr(manifest_path), update_task->update_path);
|
||||
update_task_set_progress(update_task, UpdateTaskStageProgress, 30);
|
||||
|
||||
UpdateManifest* manifest = update_task->manifest;
|
||||
if(!update_manifest_init(manifest, string_get_cstr(manifest_path))) {
|
||||
if(!update_manifest_init(manifest, furi_string_get_cstr(manifest_path))) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ bool update_task_parse_manifest(UpdateTask* update_task) {
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(manifest_path);
|
||||
furi_string_free(manifest_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,6 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <m-string.h>
|
||||
|
||||
#define UPDATE_DELAY_OPERATION_OK 10
|
||||
#define UPDATE_DELAY_OPERATION_ERROR INT_MAX
|
||||
@@ -59,7 +58,7 @@ typedef enum {
|
||||
typedef struct {
|
||||
UpdateTaskStage stage;
|
||||
uint8_t overall_progress, stage_progress;
|
||||
string_t status;
|
||||
FuriString* status;
|
||||
UpdateTaskStageGroup groups;
|
||||
uint32_t total_progress_points;
|
||||
uint32_t completed_stages_points;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
typedef struct UpdateTask {
|
||||
UpdateTaskState state;
|
||||
string_t update_path;
|
||||
FuriString* update_path;
|
||||
UpdateManifest* manifest;
|
||||
FuriThread* thread;
|
||||
Storage* storage;
|
||||
@@ -20,7 +20,7 @@ typedef struct UpdateTask {
|
||||
|
||||
void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, uint8_t progress);
|
||||
bool update_task_parse_manifest(UpdateTask* update_task);
|
||||
bool update_task_open_file(UpdateTask* update_task, string_t filename);
|
||||
bool update_task_open_file(UpdateTask* update_task, FuriString* filename);
|
||||
|
||||
int32_t update_task_worker_flash_writer(void* context);
|
||||
int32_t update_task_worker_backup_restore(void* context);
|
||||
|
@@ -22,19 +22,22 @@
|
||||
|
||||
static bool update_task_pre_update(UpdateTask* update_task) {
|
||||
bool success = false;
|
||||
string_t backup_file_path;
|
||||
string_init(backup_file_path);
|
||||
FuriString* backup_file_path;
|
||||
backup_file_path = furi_string_alloc();
|
||||
path_concat(
|
||||
string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, backup_file_path);
|
||||
furi_string_get_cstr(update_task->update_path),
|
||||
LFS_BACKUP_DEFAULT_FILENAME,
|
||||
backup_file_path);
|
||||
|
||||
update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0);
|
||||
/* to avoid bootloops */
|
||||
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
|
||||
if((success = lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) {
|
||||
if((success =
|
||||
lfs_backup_create(update_task->storage, furi_string_get_cstr(backup_file_path)))) {
|
||||
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate);
|
||||
}
|
||||
|
||||
string_clear(backup_file_path);
|
||||
furi_string_free(backup_file_path);
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -79,12 +82,12 @@ static void
|
||||
/* For this stage, first 30% of progress = cleanup */
|
||||
(n_processed_files++ * 30) / (n_approx_file_entries + 1));
|
||||
|
||||
string_t file_path;
|
||||
string_init(file_path);
|
||||
path_concat(STORAGE_EXT_PATH_PREFIX, string_get_cstr(entry_ptr->name), file_path);
|
||||
FURI_LOG_D(TAG, "Removing %s", string_get_cstr(file_path));
|
||||
storage_simply_remove(update_task->storage, string_get_cstr(file_path));
|
||||
string_clear(file_path);
|
||||
FuriString* file_path = furi_string_alloc();
|
||||
path_concat(
|
||||
STORAGE_EXT_PATH_PREFIX, furi_string_get_cstr(entry_ptr->name), file_path);
|
||||
FURI_LOG_D(TAG, "Removing %s", furi_string_get_cstr(file_path));
|
||||
storage_simply_remove(update_task->storage, furi_string_get_cstr(file_path));
|
||||
furi_string_free(file_path);
|
||||
}
|
||||
}
|
||||
} while(false);
|
||||
@@ -94,17 +97,19 @@ static void
|
||||
static bool update_task_post_update(UpdateTask* update_task) {
|
||||
bool success = false;
|
||||
|
||||
string_t file_path;
|
||||
string_init(file_path);
|
||||
FuriString* file_path;
|
||||
file_path = furi_string_alloc();
|
||||
|
||||
TarArchive* archive = tar_archive_alloc(update_task->storage);
|
||||
do {
|
||||
path_concat(
|
||||
string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, file_path);
|
||||
furi_string_get_cstr(update_task->update_path),
|
||||
LFS_BACKUP_DEFAULT_FILENAME,
|
||||
file_path);
|
||||
|
||||
update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0);
|
||||
|
||||
CHECK_RESULT(lfs_backup_unpack(update_task->storage, string_get_cstr(file_path)));
|
||||
CHECK_RESULT(lfs_backup_unpack(update_task->storage, furi_string_get_cstr(file_path)));
|
||||
|
||||
if(update_task->state.groups & UpdateTaskStageGroupResources) {
|
||||
TarUnpackProgress progress = {
|
||||
@@ -115,13 +120,13 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
||||
update_task_set_progress(update_task, UpdateTaskStageResourcesUpdate, 0);
|
||||
|
||||
path_concat(
|
||||
string_get_cstr(update_task->update_path),
|
||||
string_get_cstr(update_task->manifest->resource_bundle),
|
||||
furi_string_get_cstr(update_task->update_path),
|
||||
furi_string_get_cstr(update_task->manifest->resource_bundle),
|
||||
file_path);
|
||||
|
||||
tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress);
|
||||
CHECK_RESULT(
|
||||
tar_archive_open(archive, string_get_cstr(file_path), TAR_OPEN_MODE_READ));
|
||||
tar_archive_open(archive, furi_string_get_cstr(file_path), TAR_OPEN_MODE_READ));
|
||||
|
||||
progress.total_files = tar_archive_get_entries_count(archive);
|
||||
if(progress.total_files > 0) {
|
||||
@@ -133,23 +138,23 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
||||
|
||||
if(update_task->state.groups & UpdateTaskStageGroupSplashscreen) {
|
||||
update_task_set_progress(update_task, UpdateTaskStageSplashscreenInstall, 0);
|
||||
string_t tmp_path;
|
||||
string_init_set(tmp_path, update_task->update_path);
|
||||
path_append(tmp_path, string_get_cstr(update_task->manifest->splash_file));
|
||||
FuriString* tmp_path;
|
||||
tmp_path = furi_string_alloc_set(update_task->update_path);
|
||||
path_append(tmp_path, furi_string_get_cstr(update_task->manifest->splash_file));
|
||||
if(storage_common_copy(
|
||||
update_task->storage,
|
||||
string_get_cstr(tmp_path),
|
||||
furi_string_get_cstr(tmp_path),
|
||||
INT_PATH(SLIDESHOW_FILE_NAME)) != FSE_OK) {
|
||||
// actually, not critical
|
||||
}
|
||||
string_clear(tmp_path);
|
||||
furi_string_free(tmp_path);
|
||||
update_task_set_progress(update_task, UpdateTaskStageSplashscreenInstall, 100);
|
||||
}
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
tar_archive_free(archive);
|
||||
string_clear(file_path);
|
||||
furi_string_free(file_path);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user