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:
@@ -1,7 +1,6 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <m-string.h>
|
||||
#include <cli/cli.h>
|
||||
#include <storage/storage.h>
|
||||
#include <loader/loader.h>
|
||||
@@ -12,16 +11,16 @@
|
||||
#include <update_util/lfs_backup.h>
|
||||
#include <update_util/update_operation.h>
|
||||
|
||||
typedef void (*cmd_handler)(string_t args);
|
||||
typedef void (*cmd_handler)(FuriString* args);
|
||||
typedef struct {
|
||||
const char* command;
|
||||
const cmd_handler handler;
|
||||
} CliSubcommand;
|
||||
|
||||
static void updater_cli_install(string_t manifest_path) {
|
||||
printf("Verifying update package at '%s'\r\n", string_get_cstr(manifest_path));
|
||||
static void updater_cli_install(FuriString* manifest_path) {
|
||||
printf("Verifying update package at '%s'\r\n", furi_string_get_cstr(manifest_path));
|
||||
|
||||
UpdatePrepareResult result = update_operation_prepare(string_get_cstr(manifest_path));
|
||||
UpdatePrepareResult result = update_operation_prepare(furi_string_get_cstr(manifest_path));
|
||||
if(result != UpdatePrepareResultOK) {
|
||||
printf(
|
||||
"Error: %s. Stopping update.\r\n",
|
||||
@@ -33,23 +32,23 @@ static void updater_cli_install(string_t manifest_path) {
|
||||
furi_hal_power_reset();
|
||||
}
|
||||
|
||||
static void updater_cli_backup(string_t args) {
|
||||
printf("Backup /int to '%s'\r\n", string_get_cstr(args));
|
||||
static void updater_cli_backup(FuriString* args) {
|
||||
printf("Backup /int to '%s'\r\n", furi_string_get_cstr(args));
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool success = lfs_backup_create(storage, string_get_cstr(args));
|
||||
bool success = lfs_backup_create(storage, furi_string_get_cstr(args));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
printf("Result: %s\r\n", success ? "OK" : "FAIL");
|
||||
}
|
||||
|
||||
static void updater_cli_restore(string_t args) {
|
||||
printf("Restore /int from '%s'\r\n", string_get_cstr(args));
|
||||
static void updater_cli_restore(FuriString* args) {
|
||||
printf("Restore /int from '%s'\r\n", furi_string_get_cstr(args));
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool success = lfs_backup_unpack(storage, string_get_cstr(args));
|
||||
bool success = lfs_backup_unpack(storage, furi_string_get_cstr(args));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
printf("Result: %s\r\n", success ? "OK" : "FAIL");
|
||||
}
|
||||
|
||||
static void updater_cli_help(string_t args) {
|
||||
static void updater_cli_help(FuriString* args) {
|
||||
UNUSED(args);
|
||||
printf("Commands:\r\n"
|
||||
"\tinstall /ext/path/to/update.fuf - verify & apply update package\r\n"
|
||||
@@ -64,25 +63,25 @@ static const CliSubcommand update_cli_subcommands[] = {
|
||||
{.command = "help", .handler = updater_cli_help},
|
||||
};
|
||||
|
||||
static void updater_cli_ep(Cli* cli, string_t args, void* context) {
|
||||
static void updater_cli_ep(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
UNUSED(context);
|
||||
string_t subcommand;
|
||||
string_init(subcommand);
|
||||
if(!args_read_string_and_trim(args, subcommand) || string_empty_p(args)) {
|
||||
FuriString* subcommand;
|
||||
subcommand = furi_string_alloc();
|
||||
if(!args_read_string_and_trim(args, subcommand) || furi_string_empty(args)) {
|
||||
updater_cli_help(args);
|
||||
string_clear(subcommand);
|
||||
furi_string_free(subcommand);
|
||||
return;
|
||||
}
|
||||
for(size_t idx = 0; idx < COUNT_OF(update_cli_subcommands); ++idx) {
|
||||
const CliSubcommand* subcmd_def = &update_cli_subcommands[idx];
|
||||
if(string_cmp_str(subcommand, subcmd_def->command) == 0) {
|
||||
string_clear(subcommand);
|
||||
if(furi_string_cmp_str(subcommand, subcmd_def->command) == 0) {
|
||||
furi_string_free(subcommand);
|
||||
subcmd_def->handler(args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
string_clear(subcommand);
|
||||
furi_string_free(subcommand);
|
||||
updater_cli_help(args);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user