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 00:15:23 +09:00
committed by GitHub
co-authored by Aleksandr Kutuzov
parent 0f9ea925d3
commit 4bf29827f8
370 changed files with 5597 additions and 3963 deletions
+18 -18
View File
@@ -7,18 +7,18 @@
#include "bt_settings.h"
#include "bt_service/bt.h"
static void bt_cli_command_hci_info(Cli* cli, string_t args, void* context) {
static void bt_cli_command_hci_info(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
string_t buffer;
string_init(buffer);
FuriString* buffer;
buffer = furi_string_alloc();
furi_hal_bt_dump_state(buffer);
printf("%s", string_get_cstr(buffer));
string_clear(buffer);
printf("%s", furi_string_get_cstr(buffer));
furi_string_free(buffer);
}
static void bt_cli_command_carrier_tx(Cli* cli, string_t args, void* context) {
static void bt_cli_command_carrier_tx(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
int channel = 0;
int power = 0;
@@ -50,7 +50,7 @@ static void bt_cli_command_carrier_tx(Cli* cli, string_t args, void* context) {
} while(false);
}
static void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) {
static void bt_cli_command_carrier_rx(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
int channel = 0;
@@ -81,7 +81,7 @@ static void bt_cli_command_carrier_rx(Cli* cli, string_t args, void* context) {
} while(false);
}
static void bt_cli_command_packet_tx(Cli* cli, string_t args, void* context) {
static void bt_cli_command_packet_tx(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
int channel = 0;
int pattern = 0;
@@ -129,7 +129,7 @@ static void bt_cli_command_packet_tx(Cli* cli, string_t args, void* context) {
} while(false);
}
static void bt_cli_command_packet_rx(Cli* cli, string_t args, void* context) {
static void bt_cli_command_packet_rx(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
int channel = 0;
int datarate = 1;
@@ -178,12 +178,12 @@ static void bt_cli_print_usage() {
}
}
static void bt_cli(Cli* cli, string_t args, void* context) {
static void bt_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
furi_record_open(RECORD_BT);
string_t cmd;
string_init(cmd);
FuriString* cmd;
cmd = furi_string_alloc();
BtSettings bt_settings;
bt_settings_load(&bt_settings);
@@ -192,24 +192,24 @@ static void bt_cli(Cli* cli, string_t args, void* context) {
bt_cli_print_usage();
break;
}
if(string_cmp_str(cmd, "hci_info") == 0) {
if(furi_string_cmp_str(cmd, "hci_info") == 0) {
bt_cli_command_hci_info(cli, args, NULL);
break;
}
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) && furi_hal_bt_is_testing_supported()) {
if(string_cmp_str(cmd, "tx_carrier") == 0) {
if(furi_string_cmp_str(cmd, "tx_carrier") == 0) {
bt_cli_command_carrier_tx(cli, args, NULL);
break;
}
if(string_cmp_str(cmd, "rx_carrier") == 0) {
if(furi_string_cmp_str(cmd, "rx_carrier") == 0) {
bt_cli_command_carrier_rx(cli, args, NULL);
break;
}
if(string_cmp_str(cmd, "tx_packet") == 0) {
if(furi_string_cmp_str(cmd, "tx_packet") == 0) {
bt_cli_command_packet_tx(cli, args, NULL);
break;
}
if(string_cmp_str(cmd, "rx_packet") == 0) {
if(furi_string_cmp_str(cmd, "rx_packet") == 0) {
bt_cli_command_packet_rx(cli, args, NULL);
break;
}
@@ -222,7 +222,7 @@ static void bt_cli(Cli* cli, string_t args, void* context) {
furi_hal_bt_start_advertising();
}
string_clear(cmd);
furi_string_free(cmd);
furi_record_close(RECORD_BT);
}
+4 -4
View File
@@ -75,14 +75,14 @@ static void bt_pin_code_hide(Bt* bt) {
static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
furi_assert(bt);
notification_message(bt->notification, &sequence_display_backlight_on);
string_t pin_str;
FuriString* pin_str;
dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0);
string_init_printf(pin_str, "Verify code\n%06d", pin);
pin_str = furi_string_alloc_printf("Verify code\n%06d", pin);
dialog_message_set_text(
bt->dialog_message, string_get_cstr(pin_str), 64, 4, AlignCenter, AlignTop);
bt->dialog_message, furi_string_get_cstr(pin_str), 64, 4, AlignCenter, AlignTop);
dialog_message_set_buttons(bt->dialog_message, "Cancel", "OK", NULL);
DialogMessageButton button = dialog_message_show(bt->dialogs, bt->dialog_message);
string_clear(pin_str);
furi_string_free(pin_str);
return button == DialogMessageButtonCenter;
}
+62 -78
View File
@@ -11,8 +11,8 @@ Cli* cli_alloc() {
CliCommandTree_init(cli->commands);
string_init(cli->last_line);
string_init(cli->line);
cli->last_line = furi_string_alloc();
cli->line = furi_string_alloc();
cli->session = NULL;
@@ -138,34 +138,26 @@ void cli_nl(Cli* cli) {
void cli_prompt(Cli* cli) {
UNUSED(cli);
printf("\r\n>: %s", string_get_cstr(cli->line));
printf("\r\n>: %s", furi_string_get_cstr(cli->line));
fflush(stdout);
}
void cli_reset(Cli* cli) {
// cli->last_line is cleared and cli->line's buffer moved to cli->last_line
string_move(cli->last_line, cli->line);
furi_string_move(cli->last_line, cli->line);
// Reiniting cli->line
string_init(cli->line);
cli->line = furi_string_alloc();
cli->cursor_position = 0;
}
static void cli_handle_backspace(Cli* cli) {
if(cli->cursor_position > 0) {
furi_assert(string_size(cli->line) > 0);
furi_assert(furi_string_size(cli->line) > 0);
// Other side
printf("\e[D\e[1P");
fflush(stdout);
// Our side
string_t temp;
string_init(temp);
string_reserve(temp, string_size(cli->line) - 1);
string_set_strn(temp, string_get_cstr(cli->line), cli->cursor_position - 1);
string_cat_str(temp, string_get_cstr(cli->line) + cli->cursor_position);
// cli->line is cleared and temp's buffer moved to cli->line
string_move(cli->line, temp);
// NO MEMORY LEAK, STOP REPORTING IT
furi_string_replace_at(cli->line, cli->cursor_position - 1, 1, "");
cli->cursor_position--;
} else {
@@ -174,11 +166,11 @@ static void cli_handle_backspace(Cli* cli) {
}
static void cli_normalize_line(Cli* cli) {
string_strim(cli->line);
cli->cursor_position = string_size(cli->line);
furi_string_trim(cli->line);
cli->cursor_position = furi_string_size(cli->line);
}
static void cli_execute_command(Cli* cli, CliCommand* command, string_t args) {
static void cli_execute_command(Cli* cli, CliCommand* command, FuriString* args) {
if(!(command->flags & CliCommandFlagInsomniaSafe)) {
furi_hal_power_insomnia_enter();
}
@@ -208,25 +200,25 @@ static void cli_execute_command(Cli* cli, CliCommand* command, string_t args) {
static void cli_handle_enter(Cli* cli) {
cli_normalize_line(cli);
if(string_size(cli->line) == 0) {
if(furi_string_size(cli->line) == 0) {
cli_prompt(cli);
return;
}
// Command and args container
string_t command;
string_init(command);
string_t args;
string_init(args);
FuriString* command;
command = furi_string_alloc();
FuriString* args;
args = furi_string_alloc();
// Split command and args
size_t ws = string_search_char(cli->line, ' ');
if(ws == STRING_FAILURE) {
string_set(command, cli->line);
size_t ws = furi_string_search_char(cli->line, ' ');
if(ws == FURI_STRING_FAILURE) {
furi_string_set(command, cli->line);
} else {
string_set_n(command, cli->line, 0, ws);
string_set_n(args, cli->line, ws, string_size(cli->line));
string_strim(args);
furi_string_set_n(command, cli->line, 0, ws);
furi_string_set_n(args, cli->line, ws, furi_string_size(cli->line));
furi_string_trim(args);
}
// Search for command
@@ -244,7 +236,7 @@ static void cli_handle_enter(Cli* cli) {
cli_nl(cli);
printf(
"`%s` command not found, use `help` or `?` to list all available commands",
string_get_cstr(command));
furi_string_get_cstr(command));
cli_putc(cli, CliSymbolAsciiBell);
}
@@ -252,59 +244,59 @@ static void cli_handle_enter(Cli* cli) {
cli_prompt(cli);
// Cleanup command and args
string_clear(command);
string_clear(args);
furi_string_free(command);
furi_string_free(args);
}
static void cli_handle_autocomplete(Cli* cli) {
cli_normalize_line(cli);
if(string_size(cli->line) == 0) {
if(furi_string_size(cli->line) == 0) {
return;
}
cli_nl(cli);
// Prepare common base for autocomplete
string_t common;
string_init(common);
FuriString* common;
common = furi_string_alloc();
// Iterate throw commands
for
M_EACH(cli_command, cli->commands, CliCommandTree_t) {
// Process only if starts with line buffer
if(string_start_with_string_p(*cli_command->key_ptr, cli->line)) {
if(furi_string_start_with(*cli_command->key_ptr, cli->line)) {
// Show autocomplete option
printf("%s\r\n", string_get_cstr(*cli_command->key_ptr));
printf("%s\r\n", furi_string_get_cstr(*cli_command->key_ptr));
// Process common base for autocomplete
if(string_size(common) > 0) {
if(furi_string_size(common) > 0) {
// Choose shortest string
const size_t key_size = string_size(*cli_command->key_ptr);
const size_t common_size = string_size(common);
const size_t key_size = furi_string_size(*cli_command->key_ptr);
const size_t common_size = furi_string_size(common);
const size_t min_size = key_size > common_size ? common_size : key_size;
size_t i = 0;
while(i < min_size) {
// Stop when do not match
if(string_get_char(*cli_command->key_ptr, i) !=
string_get_char(common, i)) {
if(furi_string_get_char(*cli_command->key_ptr, i) !=
furi_string_get_char(common, i)) {
break;
}
i++;
}
// Cut right part if any
string_left(common, i);
furi_string_left(common, i);
} else {
// Start with something
string_set(common, *cli_command->key_ptr);
furi_string_set(common, *cli_command->key_ptr);
}
}
}
// Replace line buffer if autocomplete better
if(string_size(common) > string_size(cli->line)) {
string_set(cli->line, common);
cli->cursor_position = string_size(cli->line);
if(furi_string_size(common) > furi_string_size(cli->line)) {
furi_string_set(cli->line, common);
cli->cursor_position = furi_string_size(cli->line);
}
// Cleanup
string_clear(common);
furi_string_free(common);
// Show prompt
cli_prompt(cli);
}
@@ -312,16 +304,16 @@ static void cli_handle_autocomplete(Cli* cli) {
static void cli_handle_escape(Cli* cli, char c) {
if(c == 'A') {
// Use previous command if line buffer is empty
if(string_size(cli->line) == 0 && string_cmp(cli->line, cli->last_line) != 0) {
if(furi_string_size(cli->line) == 0 && furi_string_cmp(cli->line, cli->last_line) != 0) {
// Set line buffer and cursor position
string_set(cli->line, cli->last_line);
cli->cursor_position = string_size(cli->line);
furi_string_set(cli->line, cli->last_line);
cli->cursor_position = furi_string_size(cli->line);
// Show new line to user
printf("%s", string_get_cstr(cli->line));
printf("%s", furi_string_get_cstr(cli->line));
}
} else if(c == 'B') {
} else if(c == 'C') {
if(cli->cursor_position < string_size(cli->line)) {
if(cli->cursor_position < furi_string_size(cli->line)) {
cli->cursor_position++;
printf("\e[C");
}
@@ -362,21 +354,13 @@ void cli_process_input(Cli* cli) {
} else if(in_chr == CliSymbolAsciiCR) {
cli_handle_enter(cli);
} else if(in_chr >= 0x20 && in_chr < 0x7F) {
if(cli->cursor_position == string_size(cli->line)) {
string_push_back(cli->line, in_chr);
if(cli->cursor_position == furi_string_size(cli->line)) {
furi_string_push_back(cli->line, in_chr);
cli_putc(cli, in_chr);
} else {
// ToDo: better way?
string_t temp;
string_init(temp);
string_reserve(temp, string_size(cli->line) + 1);
string_set_strn(temp, string_get_cstr(cli->line), cli->cursor_position);
string_push_back(temp, in_chr);
string_cat_str(temp, string_get_cstr(cli->line) + cli->cursor_position);
// cli->line is cleared and temp's buffer moved to cli->line
string_move(cli->line, temp);
// NO MEMORY LEAK, STOP REPORTING IT
// Insert character to line buffer
const char in_str[2] = {in_chr, 0};
furi_string_replace_at(cli->line, cli->cursor_position, 0, in_str);
// Print character in replace mode
printf("\e[4h%c\e[4l", in_chr);
@@ -394,14 +378,14 @@ void cli_add_command(
CliCommandFlag flags,
CliCallback callback,
void* context) {
string_t name_str;
string_init_set_str(name_str, name);
string_strim(name_str);
FuriString* name_str;
name_str = furi_string_alloc_set(name);
furi_string_trim(name_str);
size_t name_replace;
do {
name_replace = string_replace_str(name_str, " ", "_");
} while(name_replace != STRING_FAILURE);
name_replace = furi_string_replace(name_str, " ", "_");
} while(name_replace != FURI_STRING_FAILURE);
CliCommand c;
c.callback = callback;
@@ -412,24 +396,24 @@ void cli_add_command(
CliCommandTree_set_at(cli->commands, name_str, c);
furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk);
string_clear(name_str);
furi_string_free(name_str);
}
void cli_delete_command(Cli* cli, const char* name) {
string_t name_str;
string_init_set_str(name_str, name);
string_strim(name_str);
FuriString* name_str;
name_str = furi_string_alloc_set(name);
furi_string_trim(name_str);
size_t name_replace;
do {
name_replace = string_replace_str(name_str, " ", "_");
} while(name_replace != STRING_FAILURE);
name_replace = furi_string_replace(name_str, " ", "_");
} while(name_replace != FURI_STRING_FAILURE);
furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk);
CliCommandTree_erase(cli->commands, name_str);
furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk);
string_clear(name_str);
furi_string_free(name_str);
}
void cli_session_open(Cli* cli, void* session) {
+2 -3
View File
@@ -4,8 +4,7 @@
*/
#pragma once
#include <m-string.h>
#include <furi.h>
#ifdef __cplusplus
extern "C" {
@@ -43,7 +42,7 @@ typedef struct Cli Cli;
* @param args string with what was passed after command
* @param context pointer to whatever you gave us on cli_add_command
*/
typedef void (*CliCallback)(Cli* cli, string_t args, void* context);
typedef void (*CliCallback)(Cli* cli, FuriString* args, void* context);
/** Add cli command Registers you command callback
*
+26 -26
View File
@@ -35,11 +35,11 @@ void cli_command_gpio_print_usage() {
printf("\tread <pin_name>\t - Read gpio value\r\n");
}
static bool pin_name_to_int(string_t pin_name, size_t* result) {
static bool pin_name_to_int(FuriString* pin_name, size_t* result) {
bool found = false;
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
if(!string_cmp(pin_name, cli_command_gpio_pins[i].name)) {
if(!furi_string_cmp(pin_name, cli_command_gpio_pins[i].name)) {
if(!cli_command_gpio_pins[i].debug || (cli_command_gpio_pins[i].debug && debug)) {
*result = i;
found = true;
@@ -63,29 +63,29 @@ static void gpio_print_pins(void) {
typedef enum { OK, ERR_CMD_SYNTAX, ERR_PIN, ERR_VALUE } GpioParseError;
static GpioParseError gpio_command_parse(string_t args, size_t* pin_num, uint8_t* value) {
string_t pin_name;
string_init(pin_name);
static GpioParseError gpio_command_parse(FuriString* args, size_t* pin_num, uint8_t* value) {
FuriString* pin_name;
pin_name = furi_string_alloc();
size_t ws = string_search_char(args, ' ');
if(ws == STRING_FAILURE) {
size_t ws = furi_string_search_char(args, ' ');
if(ws == FURI_STRING_FAILURE) {
return ERR_CMD_SYNTAX;
}
string_set_n(pin_name, args, 0, ws);
string_right(args, ws);
string_strim(args);
furi_string_set_n(pin_name, args, 0, ws);
furi_string_right(args, ws);
furi_string_trim(args);
if(!pin_name_to_int(pin_name, pin_num)) {
string_clear(pin_name);
furi_string_free(pin_name);
return ERR_PIN;
}
string_clear(pin_name);
furi_string_free(pin_name);
if(!string_cmp(args, "0")) {
if(!furi_string_cmp(args, "0")) {
*value = 0;
} else if(!string_cmp(args, "1")) {
} else if(!furi_string_cmp(args, "1")) {
*value = 1;
} else {
return ERR_VALUE;
@@ -94,7 +94,7 @@ static GpioParseError gpio_command_parse(string_t args, size_t* pin_num, uint8_t
return OK;
}
void cli_command_gpio_mode(Cli* cli, string_t args, void* context) {
void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
@@ -104,7 +104,7 @@ void cli_command_gpio_mode(Cli* cli, string_t args, void* context) {
GpioParseError err = gpio_command_parse(args, &num, &value);
if(ERR_CMD_SYNTAX == err) {
cli_print_usage("gpio mode", "<pin_name> <0|1>", string_get_cstr(args));
cli_print_usage("gpio mode", "<pin_name> <0|1>", furi_string_get_cstr(args));
return;
} else if(ERR_PIN == err) {
gpio_print_pins();
@@ -134,7 +134,7 @@ void cli_command_gpio_mode(Cli* cli, string_t args, void* context) {
}
}
void cli_command_gpio_read(Cli* cli, string_t args, void* context) {
void cli_command_gpio_read(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
@@ -156,7 +156,7 @@ void cli_command_gpio_read(Cli* cli, string_t args, void* context) {
printf("Pin %s <= %u", cli_command_gpio_pins[num].name, val);
}
void cli_command_gpio_set(Cli* cli, string_t args, void* context) {
void cli_command_gpio_set(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
size_t num = 0;
@@ -164,7 +164,7 @@ void cli_command_gpio_set(Cli* cli, string_t args, void* context) {
GpioParseError err = gpio_command_parse(args, &num, &value);
if(ERR_CMD_SYNTAX == err) {
cli_print_usage("gpio set", "<pin_name> <0|1>", string_get_cstr(args));
cli_print_usage("gpio set", "<pin_name> <0|1>", furi_string_get_cstr(args));
return;
} else if(ERR_PIN == err) {
gpio_print_pins();
@@ -196,9 +196,9 @@ void cli_command_gpio_set(Cli* cli, string_t args, void* context) {
printf("Pin %s => %u", cli_command_gpio_pins[num].name, !!value);
}
void cli_command_gpio(Cli* cli, string_t args, void* context) {
string_t cmd;
string_init(cmd);
void cli_command_gpio(Cli* cli, FuriString* args, void* context) {
FuriString* cmd;
cmd = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
@@ -206,17 +206,17 @@ void cli_command_gpio(Cli* cli, string_t args, void* context) {
break;
}
if(string_cmp_str(cmd, "mode") == 0) {
if(furi_string_cmp_str(cmd, "mode") == 0) {
cli_command_gpio_mode(cli, args, context);
break;
}
if(string_cmp_str(cmd, "set") == 0) {
if(furi_string_cmp_str(cmd, "set") == 0) {
cli_command_gpio_set(cli, args, context);
break;
}
if(string_cmp_str(cmd, "read") == 0) {
if(furi_string_cmp_str(cmd, "read") == 0) {
cli_command_gpio_read(cli, args, context);
break;
}
@@ -224,5 +224,5 @@ void cli_command_gpio(Cli* cli, string_t args, void* context) {
cli_command_gpio_print_usage();
} while(false);
string_clear(cmd);
furi_string_free(cmd);
}
+1 -1
View File
@@ -2,4 +2,4 @@
#include "cli_i.h"
void cli_command_gpio(Cli* cli, string_t args, void* context);
void cli_command_gpio(Cli* cli, FuriString* args, void* context);
+42 -42
View File
@@ -22,13 +22,13 @@ void cli_command_device_info_callback(const char* key, const char* value, bool l
* Device Info Command
* This command is intended to be used by humans
*/
void cli_command_device_info(Cli* cli, string_t args, void* context) {
void cli_command_device_info(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
furi_hal_info_get(cli_command_device_info_callback, context);
}
void cli_command_help(Cli* cli, string_t args, void* context) {
void cli_command_help(Cli* cli, FuriString* args, void* context) {
UNUSED(args);
UNUSED(context);
printf("Commands we have:");
@@ -49,34 +49,34 @@ void cli_command_help(Cli* cli, string_t args, void* context) {
printf("\r\n");
// Left Column
if(!CliCommandTree_end_p(it_left)) {
printf("%-30s", string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr));
printf("%-30s", furi_string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr));
CliCommandTree_next(it_left);
}
// Right Column
if(!CliCommandTree_end_p(it_right)) {
printf("%s", string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr));
printf("%s", furi_string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr));
CliCommandTree_next(it_right);
}
};
if(string_size(args) > 0) {
if(furi_string_size(args) > 0) {
cli_nl();
printf("Also I have no clue what '");
printf("%s", string_get_cstr(args));
printf("%s", furi_string_get_cstr(args));
printf("' is.");
}
}
void cli_command_date(Cli* cli, string_t args, void* context) {
void cli_command_date(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
FuriHalRtcDateTime datetime = {0};
if(string_size(args) > 0) {
if(furi_string_size(args) > 0) {
uint16_t hours, minutes, seconds, month, day, year, weekday;
int ret = sscanf(
string_get_cstr(args),
furi_string_get_cstr(args),
"%hu-%hu-%hu %hu:%hu:%hu %hu",
&year,
&month,
@@ -101,7 +101,7 @@ void cli_command_date(Cli* cli, string_t args, void* context) {
"Invalid datetime format, use `%s`. sscanf %d %s",
"%Y-%m-%d %H:%M:%S %u",
ret,
string_get_cstr(args));
furi_string_get_cstr(args));
return;
}
@@ -143,7 +143,7 @@ void cli_command_log_tx_callback(const uint8_t* buffer, size_t size, void* conte
xStreamBufferSend(context, buffer, size, 0);
}
void cli_command_log(Cli* cli, string_t args, void* context) {
void cli_command_log(Cli* cli, FuriString* args, void* context) {
UNUSED(args);
UNUSED(context);
StreamBufferHandle_t ring = xStreamBufferCreate(CLI_COMMAND_LOG_RING_SIZE, 1);
@@ -162,75 +162,75 @@ void cli_command_log(Cli* cli, string_t args, void* context) {
vStreamBufferDelete(ring);
}
void cli_command_vibro(Cli* cli, string_t args, void* context) {
void cli_command_vibro(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
if(!string_cmp(args, "0")) {
if(!furi_string_cmp(args, "0")) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message_block(notification, &sequence_reset_vibro);
furi_record_close(RECORD_NOTIFICATION);
} else if(!string_cmp(args, "1")) {
} else if(!furi_string_cmp(args, "1")) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message_block(notification, &sequence_set_vibro_on);
furi_record_close(RECORD_NOTIFICATION);
} else {
cli_print_usage("vibro", "<1|0>", string_get_cstr(args));
cli_print_usage("vibro", "<1|0>", furi_string_get_cstr(args));
}
}
void cli_command_debug(Cli* cli, string_t args, void* context) {
void cli_command_debug(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
if(!string_cmp(args, "0")) {
if(!furi_string_cmp(args, "0")) {
furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug);
loader_update_menu();
printf("Debug disabled.");
} else if(!string_cmp(args, "1")) {
} else if(!furi_string_cmp(args, "1")) {
furi_hal_rtc_set_flag(FuriHalRtcFlagDebug);
loader_update_menu();
printf("Debug enabled.");
} else {
cli_print_usage("debug", "<1|0>", string_get_cstr(args));
cli_print_usage("debug", "<1|0>", furi_string_get_cstr(args));
}
}
void cli_command_led(Cli* cli, string_t args, void* context) {
void cli_command_led(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(context);
// Get first word as light name
NotificationMessage notification_led_message;
string_t light_name;
string_init(light_name);
size_t ws = string_search_char(args, ' ');
if(ws == STRING_FAILURE) {
cli_print_usage("led", "<r|g|b|bl> <0-255>", string_get_cstr(args));
string_clear(light_name);
FuriString* light_name;
light_name = furi_string_alloc();
size_t ws = furi_string_search_char(args, ' ');
if(ws == FURI_STRING_FAILURE) {
cli_print_usage("led", "<r|g|b|bl> <0-255>", furi_string_get_cstr(args));
furi_string_free(light_name);
return;
} else {
string_set_n(light_name, args, 0, ws);
string_right(args, ws);
string_strim(args);
furi_string_set_n(light_name, args, 0, ws);
furi_string_right(args, ws);
furi_string_trim(args);
}
// Check light name
if(!string_cmp(light_name, "r")) {
if(!furi_string_cmp(light_name, "r")) {
notification_led_message.type = NotificationMessageTypeLedRed;
} else if(!string_cmp(light_name, "g")) {
} else if(!furi_string_cmp(light_name, "g")) {
notification_led_message.type = NotificationMessageTypeLedGreen;
} else if(!string_cmp(light_name, "b")) {
} else if(!furi_string_cmp(light_name, "b")) {
notification_led_message.type = NotificationMessageTypeLedBlue;
} else if(!string_cmp(light_name, "bl")) {
} else if(!furi_string_cmp(light_name, "bl")) {
notification_led_message.type = NotificationMessageTypeLedDisplayBacklight;
} else {
cli_print_usage("led", "<r|g|b|bl> <0-255>", string_get_cstr(args));
string_clear(light_name);
cli_print_usage("led", "<r|g|b|bl> <0-255>", furi_string_get_cstr(args));
furi_string_free(light_name);
return;
}
string_clear(light_name);
furi_string_free(light_name);
// Read light value from the rest of the string
char* end_ptr;
uint32_t value = strtoul(string_get_cstr(args), &end_ptr, 0);
uint32_t value = strtoul(furi_string_get_cstr(args), &end_ptr, 0);
if(!(value < 256 && *end_ptr == '\0')) {
cli_print_usage("led", "<r|g|b|bl> <0-255>", string_get_cstr(args));
cli_print_usage("led", "<r|g|b|bl> <0-255>", furi_string_get_cstr(args));
return;
}
@@ -249,7 +249,7 @@ void cli_command_led(Cli* cli, string_t args, void* context) {
furi_record_close(RECORD_NOTIFICATION);
}
void cli_command_ps(Cli* cli, string_t args, void* context) {
void cli_command_ps(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
@@ -272,7 +272,7 @@ void cli_command_ps(Cli* cli, string_t args, void* context) {
printf("\r\nTotal: %d", thread_num);
}
void cli_command_free(Cli* cli, string_t args, void* context) {
void cli_command_free(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
@@ -286,7 +286,7 @@ void cli_command_free(Cli* cli, string_t args, void* context) {
printf("Maximum pool block: %d\r\n", memmgr_pool_get_max_block());
}
void cli_command_free_blocks(Cli* cli, string_t args, void* context) {
void cli_command_free_blocks(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
@@ -294,7 +294,7 @@ void cli_command_free_blocks(Cli* cli, string_t args, void* context) {
memmgr_heap_printf_free_blocks();
}
void cli_command_i2c(Cli* cli, string_t args, void* context) {
void cli_command_i2c(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
+4 -4
View File
@@ -36,8 +36,8 @@ struct CliSession {
BPTREE_DEF2(
CliCommandTree,
CLI_COMMANDS_TREE_RANK,
string_t,
STRING_OPLIST,
FuriString*,
FURI_STRING_OPLIST,
CliCommand,
M_POD_OPLIST)
@@ -47,8 +47,8 @@ struct Cli {
CliCommandTree_t commands;
FuriMutex* mutex;
FuriSemaphore* idle_sem;
string_t last_line;
string_t line;
FuriString* last_line;
FuriString* line;
CliSession* session;
size_t cursor_position;
+33 -32
View File
@@ -17,7 +17,7 @@ void crypto_cli_print_usage() {
"\tstore_key <key_slot:int> <key_type:str> <key_size:int> <key_data:hex>\t - Store key in secure enclave. !!! NON-REVERSABLE OPERATION - READ MANUAL FIRST !!!\r\n");
};
void crypto_cli_encrypt(Cli* cli, string_t args) {
void crypto_cli_encrypt(Cli* cli, FuriString* args) {
int key_slot = 0;
bool key_loaded = false;
uint8_t iv[16];
@@ -41,8 +41,8 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
printf("Enter plain text and press Ctrl+C to complete encryption:\r\n");
string_t input;
string_init(input);
FuriString* input;
input = furi_string_alloc();
char c;
while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
if(c == CliSymbolAsciiETX) {
@@ -51,14 +51,14 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
} else if(c >= 0x20 && c < 0x7F) {
putc(c, stdout);
fflush(stdout);
string_push_back(input, c);
furi_string_push_back(input, c);
} else if(c == CliSymbolAsciiCR) {
printf("\r\n");
string_cat_str(input, "\r\n");
furi_string_cat(input, "\r\n");
}
}
size_t size = string_size(input);
size_t size = furi_string_size(input);
if(size > 0) {
// C-string null termination and block alignments
size++;
@@ -66,9 +66,10 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
if(remain) {
size = size - remain + 16;
}
string_reserve(input, size);
furi_string_reserve(input, size);
uint8_t* output = malloc(size);
if(!furi_hal_crypto_encrypt((const uint8_t*)string_get_cstr(input), output, size)) {
if(!furi_hal_crypto_encrypt(
(const uint8_t*)furi_string_get_cstr(input), output, size)) {
printf("Failed to encrypt input");
} else {
printf("Hex-encoded encrypted data:\r\n");
@@ -83,7 +84,7 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
printf("No input");
}
string_clear(input);
furi_string_free(input);
} while(0);
if(key_loaded) {
@@ -91,7 +92,7 @@ void crypto_cli_encrypt(Cli* cli, string_t args) {
}
}
void crypto_cli_decrypt(Cli* cli, string_t args) {
void crypto_cli_decrypt(Cli* cli, FuriString* args) {
int key_slot = 0;
bool key_loaded = false;
uint8_t iv[16];
@@ -115,8 +116,8 @@ void crypto_cli_decrypt(Cli* cli, string_t args) {
printf("Enter Hex-encoded data and press Ctrl+C to complete decryption:\r\n");
string_t hex_input;
string_init(hex_input);
FuriString* hex_input;
hex_input = furi_string_alloc();
char c;
while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
if(c == CliSymbolAsciiETX) {
@@ -125,14 +126,14 @@ void crypto_cli_decrypt(Cli* cli, string_t args) {
} else if(c >= 0x20 && c < 0x7F) {
putc(c, stdout);
fflush(stdout);
string_push_back(hex_input, c);
furi_string_push_back(hex_input, c);
} else if(c == CliSymbolAsciiCR) {
printf("\r\n");
}
}
string_strim(hex_input);
size_t hex_size = string_size(hex_input);
furi_string_trim(hex_input);
size_t hex_size = furi_string_size(hex_input);
if(hex_size > 0 && hex_size % 2 == 0) {
size_t size = hex_size / 2;
uint8_t* input = malloc(size);
@@ -155,7 +156,7 @@ void crypto_cli_decrypt(Cli* cli, string_t args) {
printf("Invalid or empty input");
}
string_clear(hex_input);
furi_string_free(hex_input);
} while(0);
if(key_loaded) {
@@ -163,7 +164,7 @@ void crypto_cli_decrypt(Cli* cli, string_t args) {
}
}
void crypto_cli_has_key(Cli* cli, string_t args) {
void crypto_cli_has_key(Cli* cli, FuriString* args) {
UNUSED(cli);
int key_slot = 0;
uint8_t iv[16];
@@ -185,12 +186,12 @@ void crypto_cli_has_key(Cli* cli, string_t args) {
} while(0);
}
void crypto_cli_store_key(Cli* cli, string_t args) {
void crypto_cli_store_key(Cli* cli, FuriString* args) {
UNUSED(cli);
int key_slot = 0;
int key_size = 0;
string_t key_type;
string_init(key_type);
FuriString* key_type;
key_type = furi_string_alloc();
uint8_t data[32 + 12] = {};
FuriHalCryptoKey key;
@@ -207,19 +208,19 @@ void crypto_cli_store_key(Cli* cli, string_t args) {
break;
}
if(string_cmp_str(key_type, "master") == 0) {
if(furi_string_cmp_str(key_type, "master") == 0) {
if(key_slot != 0) {
printf("Master keyslot must be is 0");
break;
}
key.type = FuriHalCryptoKeyTypeMaster;
} else if(string_cmp_str(key_type, "simple") == 0) {
} else if(furi_string_cmp_str(key_type, "simple") == 0) {
if(key_slot < 1 || key_slot > 99) {
printf("Simple keyslot must be in range");
break;
}
key.type = FuriHalCryptoKeyTypeSimple;
} else if(string_cmp_str(key_type, "encrypted") == 0) {
} else if(furi_string_cmp_str(key_type, "encrypted") == 0) {
key.type = FuriHalCryptoKeyTypeEncrypted;
data_size += 12;
} else {
@@ -275,13 +276,13 @@ void crypto_cli_store_key(Cli* cli, string_t args) {
}
} while(0);
string_clear(key_type);
furi_string_free(key_type);
}
static void crypto_cli(Cli* cli, string_t args, void* context) {
static void crypto_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
string_t cmd;
string_init(cmd);
FuriString* cmd;
cmd = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
@@ -289,22 +290,22 @@ static void crypto_cli(Cli* cli, string_t args, void* context) {
break;
}
if(string_cmp_str(cmd, "encrypt") == 0) {
if(furi_string_cmp_str(cmd, "encrypt") == 0) {
crypto_cli_encrypt(cli, args);
break;
}
if(string_cmp_str(cmd, "decrypt") == 0) {
if(furi_string_cmp_str(cmd, "decrypt") == 0) {
crypto_cli_decrypt(cli, args);
break;
}
if(string_cmp_str(cmd, "has_key") == 0) {
if(furi_string_cmp_str(cmd, "has_key") == 0) {
crypto_cli_has_key(cli, args);
break;
}
if(string_cmp_str(cmd, "store_key") == 0) {
if(furi_string_cmp_str(cmd, "store_key") == 0) {
crypto_cli_store_key(cli, args);
break;
}
@@ -312,7 +313,7 @@ static void crypto_cli(Cli* cli, string_t args, void* context) {
crypto_cli_print_usage();
} while(false);
string_clear(cmd);
furi_string_free(cmd);
}
void crypto_on_system_start() {
@@ -2,7 +2,6 @@
#include <stdint.h>
#include <furi.h>
#include <furi_hal.h>
#include <m-string.h>
#include <portmacro.h>
#include <dolphin/dolphin.h>
#include <power/power_service/power.h>
@@ -50,7 +49,7 @@ struct AnimationManager {
AnimationManagerSetNewIdleAnimationCallback new_idle_callback;
AnimationManagerSetNewIdleAnimationCallback check_blocking_callback;
void* context;
string_t freezed_animation_name;
FuriString* freezed_animation_name;
int32_t freezed_animation_time_left;
ViewStack* view_stack;
};
@@ -279,7 +278,7 @@ AnimationManager* animation_manager_alloc(void) {
animation_manager->view_stack = view_stack_alloc();
View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
view_stack_add_view(animation_manager->view_stack, animation_view);
string_init(animation_manager->freezed_animation_name);
animation_manager->freezed_animation_name = furi_string_alloc();
animation_manager->idle_animation_timer =
furi_timer_alloc(animation_manager_timer_callback, FuriTimerTypeOnce, animation_manager);
@@ -317,7 +316,7 @@ void animation_manager_free(AnimationManager* animation_manager) {
storage_get_pubsub(storage), animation_manager->pubsub_subscription_storage);
furi_record_close(RECORD_STORAGE);
string_clear(animation_manager->freezed_animation_name);
furi_string_free(animation_manager->freezed_animation_name);
View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
view_stack_remove_view(animation_manager->view_stack, animation_view);
bubble_animation_view_free(animation_manager->animation_view);
@@ -433,7 +432,7 @@ bool animation_manager_is_animation_loaded(AnimationManager* animation_manager)
void animation_manager_unload_and_stall_animation(AnimationManager* animation_manager) {
furi_assert(animation_manager);
furi_assert(animation_manager->current_animation);
furi_assert(!string_size(animation_manager->freezed_animation_name));
furi_assert(!furi_string_size(animation_manager->freezed_animation_name));
furi_assert(
(animation_manager->state == AnimationManagerStateIdle) ||
(animation_manager->state == AnimationManagerStateBlocked));
@@ -461,7 +460,7 @@ void animation_manager_unload_and_stall_animation(AnimationManager* animation_ma
StorageAnimationManifestInfo* meta =
animation_storage_get_meta(animation_manager->current_animation);
/* copy str, not move, because it can be internal animation */
string_set_str(animation_manager->freezed_animation_name, meta->name);
furi_string_set(animation_manager->freezed_animation_name, meta->name);
bubble_animation_freeze(animation_manager->animation_view);
animation_storage_free_storage_animation(&animation_manager->current_animation);
@@ -470,14 +469,14 @@ void animation_manager_unload_and_stall_animation(AnimationManager* animation_ma
void animation_manager_load_and_continue_animation(AnimationManager* animation_manager) {
furi_assert(animation_manager);
furi_assert(!animation_manager->current_animation);
furi_assert(string_size(animation_manager->freezed_animation_name));
furi_assert(furi_string_size(animation_manager->freezed_animation_name));
furi_assert(
(animation_manager->state == AnimationManagerStateFreezedIdle) ||
(animation_manager->state == AnimationManagerStateFreezedBlocked));
if(animation_manager->state == AnimationManagerStateFreezedBlocked) {
StorageAnimation* restore_animation = animation_storage_find_animation(
string_get_cstr(animation_manager->freezed_animation_name));
furi_string_get_cstr(animation_manager->freezed_animation_name));
/* all blocked animations must be in flipper -> we can
* always find blocking animation */
furi_assert(restore_animation);
@@ -489,7 +488,7 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
if(!blocked) {
/* if no blocking - try restore last one idle */
StorageAnimation* restore_animation = animation_storage_find_animation(
string_get_cstr(animation_manager->freezed_animation_name));
furi_string_get_cstr(animation_manager->freezed_animation_name));
if(restore_animation) {
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
DolphinStats stats = dolphin_stats(dolphin);
@@ -517,7 +516,7 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
FURI_LOG_E(
TAG,
"Failed to restore \'%s\'",
string_get_cstr(animation_manager->freezed_animation_name));
furi_string_get_cstr(animation_manager->freezed_animation_name));
}
}
} else {
@@ -535,7 +534,7 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
animation_storage_get_meta(animation_manager->current_animation)->name);
bubble_animation_unfreeze(animation_manager->animation_view);
string_reset(animation_manager->freezed_animation_name);
furi_string_reset(animation_manager->freezed_animation_name);
furi_assert(animation_manager->current_animation);
}
@@ -5,7 +5,6 @@
#include <core/dangerous_defines.h>
#include <storage/storage.h>
#include <gui/icon_i.h>
#include <m-string.h>
#include "animation_manager.h"
#include "animation_storage.h"
@@ -32,8 +31,8 @@ static bool animation_storage_load_single_manifest_info(
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* file = flipper_format_file_alloc(storage);
flipper_format_set_strict_mode(file, true);
string_t read_string;
string_init(read_string);
FuriString* read_string;
read_string = furi_string_alloc();
do {
uint32_t u32value;
@@ -41,20 +40,20 @@ static bool animation_storage_load_single_manifest_info(
if(!flipper_format_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
if(!flipper_format_read_header(file, read_string, &u32value)) break;
if(string_cmp_str(read_string, "Flipper Animation Manifest")) break;
if(furi_string_cmp_str(read_string, "Flipper Animation Manifest")) break;
manifest_info->name = NULL;
/* skip other animation names */
flipper_format_set_strict_mode(file, false);
while(flipper_format_read_string(file, "Name", read_string) &&
string_cmp_str(read_string, name))
furi_string_cmp_str(read_string, name))
;
if(string_cmp_str(read_string, name)) break;
if(furi_string_cmp_str(read_string, name)) break;
flipper_format_set_strict_mode(file, true);
manifest_info->name = malloc(string_size(read_string) + 1);
strcpy((char*)manifest_info->name, string_get_cstr(read_string));
manifest_info->name = malloc(furi_string_size(read_string) + 1);
strcpy((char*)manifest_info->name, furi_string_get_cstr(read_string));
if(!flipper_format_read_uint32(file, "Min butthurt", &u32value, 1)) break;
manifest_info->min_butthurt = u32value;
@@ -72,7 +71,7 @@ static bool animation_storage_load_single_manifest_info(
if(!result && manifest_info->name) {
free((void*)manifest_info->name);
}
string_clear(read_string);
furi_string_free(read_string);
flipper_format_free(file);
furi_record_close(RECORD_STORAGE);
@@ -88,8 +87,8 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
FlipperFormat* file = flipper_format_file_alloc(storage);
/* Forbid skipping fields */
flipper_format_set_strict_mode(file, true);
string_t read_string;
string_init(read_string);
FuriString* read_string;
read_string = furi_string_alloc();
do {
uint32_t u32value;
@@ -98,7 +97,7 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
if(FSE_OK != storage_sd_status(storage)) break;
if(!flipper_format_file_open_existing(file, ANIMATION_MANIFEST_FILE)) break;
if(!flipper_format_read_header(file, read_string, &u32value)) break;
if(string_cmp_str(read_string, "Flipper Animation Manifest")) break;
if(furi_string_cmp_str(read_string, "Flipper Animation Manifest")) break;
do {
storage_animation = malloc(sizeof(StorageAnimation));
storage_animation->external = true;
@@ -106,8 +105,9 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
storage_animation->manifest_info.name = NULL;
if(!flipper_format_read_string(file, "Name", read_string)) break;
storage_animation->manifest_info.name = malloc(string_size(read_string) + 1);
strcpy((char*)storage_animation->manifest_info.name, string_get_cstr(read_string));
storage_animation->manifest_info.name = malloc(furi_string_size(read_string) + 1);
strcpy(
(char*)storage_animation->manifest_info.name, furi_string_get_cstr(read_string));
if(!flipper_format_read_uint32(file, "Min butthurt", &u32value, 1)) break;
storage_animation->manifest_info.min_butthurt = u32value;
@@ -126,7 +126,7 @@ void animation_storage_fill_animation_list(StorageAnimationList_t* animation_lis
animation_storage_free_storage_animation(&storage_animation);
} while(0);
string_clear(read_string);
furi_string_free(read_string);
flipper_format_free(file);
// add hard-coded animations
@@ -231,16 +231,16 @@ void animation_storage_free_storage_animation(StorageAnimation** storage_animati
*storage_animation = NULL;
}
static bool animation_storage_cast_align(string_t align_str, Align* align) {
if(!string_cmp_str(align_str, "Bottom")) {
static bool animation_storage_cast_align(FuriString* align_str, Align* align) {
if(!furi_string_cmp(align_str, "Bottom")) {
*align = AlignBottom;
} else if(!string_cmp_str(align_str, "Top")) {
} else if(!furi_string_cmp(align_str, "Top")) {
*align = AlignTop;
} else if(!string_cmp_str(align_str, "Left")) {
} else if(!furi_string_cmp(align_str, "Left")) {
*align = AlignLeft;
} else if(!string_cmp_str(align_str, "Right")) {
} else if(!furi_string_cmp(align_str, "Right")) {
*align = AlignRight;
} else if(!string_cmp_str(align_str, "Center")) {
} else if(!furi_string_cmp(align_str, "Center")) {
*align = AlignCenter;
} else {
return false;
@@ -291,15 +291,16 @@ static bool animation_storage_load_frames(
bool frames_ok = false;
File* file = storage_file_alloc(storage);
FileInfo file_info;
string_t filename;
string_init(filename);
FuriString* filename;
filename = furi_string_alloc();
size_t max_filesize = ROUND_UP_TO(width, 8) * height + 1;
for(int i = 0; i < icon->frame_count; ++i) {
frames_ok = false;
string_printf(filename, ANIMATION_DIR "/%s/frame_%d.bm", name, i);
furi_string_printf(filename, ANIMATION_DIR "/%s/frame_%d.bm", name, i);
if(storage_common_stat(storage, string_get_cstr(filename), &file_info) != FSE_OK) break;
if(storage_common_stat(storage, furi_string_get_cstr(filename), &file_info) != FSE_OK)
break;
if(file_info.size > max_filesize) {
FURI_LOG_E(
TAG,
@@ -310,14 +311,15 @@ static bool animation_storage_load_frames(
height);
break;
}
if(!storage_file_open(file, string_get_cstr(filename), FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_E(TAG, "Can't open file \'%s\'", string_get_cstr(filename));
if(!storage_file_open(
file, furi_string_get_cstr(filename), FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_E(TAG, "Can't open file \'%s\'", furi_string_get_cstr(filename));
break;
}
FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(file_info.size));
if(storage_file_read(file, (void*)icon->frames[i], file_info.size) != file_info.size) {
FURI_LOG_E(TAG, "Read failed: \'%s\'", string_get_cstr(filename));
FURI_LOG_E(TAG, "Read failed: \'%s\'", furi_string_get_cstr(filename));
break;
}
storage_file_close(file);
@@ -328,7 +330,7 @@ static bool animation_storage_load_frames(
FURI_LOG_E(
TAG,
"Load \'%s\' failed, %dx%d, size: %d",
string_get_cstr(filename),
furi_string_get_cstr(filename),
width,
height,
file_info.size);
@@ -341,15 +343,15 @@ static bool animation_storage_load_frames(
}
storage_file_free(file);
string_clear(filename);
furi_string_free(filename);
return frames_ok;
}
static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFormat* ff) {
uint32_t u32value;
string_t str;
string_init(str);
FuriString* str;
str = furi_string_alloc();
bool success = false;
furi_assert(!animation->frame_bubble_sequences);
@@ -396,12 +398,12 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFo
FURI_CONST_ASSIGN(bubble->bubble.y, u32value);
if(!flipper_format_read_string(ff, "Text", str)) break;
if(string_size(str) > 100) break;
if(furi_string_size(str) > 100) break;
string_replace_all_str(str, "\\n", "\n");
furi_string_replace_all(str, "\\n", "\n");
FURI_CONST_ASSIGN_PTR(bubble->bubble.text, malloc(string_size(str) + 1));
strcpy((char*)bubble->bubble.text, string_get_cstr(str));
FURI_CONST_ASSIGN_PTR(bubble->bubble.text, malloc(furi_string_size(str) + 1));
strcpy((char*)bubble->bubble.text, furi_string_get_cstr(str));
if(!flipper_format_read_string(ff, "AlignH", str)) break;
if(!animation_storage_cast_align(str, (Align*)&bubble->bubble.align_h)) break;
@@ -423,7 +425,7 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFo
}
}
string_clear(str);
furi_string_free(str);
return success;
}
@@ -438,8 +440,8 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
FlipperFormat* ff = flipper_format_file_alloc(storage);
/* Forbid skipping fields */
flipper_format_set_strict_mode(ff, true);
string_t str;
string_init(str);
FuriString* str;
str = furi_string_alloc();
animation->frame_bubble_sequences = NULL;
bool success = false;
@@ -448,10 +450,10 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
if(FSE_OK != storage_sd_status(storage)) break;
string_printf(str, ANIMATION_DIR "/%s/" ANIMATION_META_FILE, name);
if(!flipper_format_file_open_existing(ff, string_get_cstr(str))) break;
furi_string_printf(str, ANIMATION_DIR "/%s/" ANIMATION_META_FILE, name);
if(!flipper_format_file_open_existing(ff, furi_string_get_cstr(str))) break;
if(!flipper_format_read_header(ff, str, &u32value)) break;
if(string_cmp_str(str, "Flipper Animation")) break;
if(furi_string_cmp_str(str, "Flipper Animation")) break;
if(!flipper_format_read_uint32(ff, "Width", &width, 1)) break;
if(!flipper_format_read_uint32(ff, "Height", &height, 1)) break;
@@ -492,7 +494,7 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
success = true;
} while(0);
string_clear(str);
furi_string_free(str);
flipper_format_free(ff);
if(u32array) {
free(u32array);
@@ -2,7 +2,6 @@
#include <stdint.h>
#include <m-list.h>
#include "views/bubble_animation_view.h"
#include <m-string.h>
/** Main structure to handle animation data.
* Contains all, including animation playing data (BubbleAnimation),
+2 -3
View File
@@ -1,7 +1,6 @@
#pragma once
#include <furi.h>
#include <gui/canvas.h>
#include "m-string.h"
#include <gui/modules/file_browser.h>
#ifdef __cplusplus
@@ -56,8 +55,8 @@ void dialog_file_browser_set_basic_options(
*/
bool dialog_file_browser_show(
DialogsApp* context,
string_ptr result_path,
string_ptr path,
FuriString* result_path,
FuriString* path,
const DialogsFileBrowserOptions* options);
/****************** MESSAGE ******************/
+2 -3
View File
@@ -1,14 +1,13 @@
#include "dialogs/dialogs_message.h"
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include "m-string.h"
/****************** File browser ******************/
bool dialog_file_browser_show(
DialogsApp* context,
string_ptr result_path,
string_ptr path,
FuriString* result_path,
FuriString* path,
const DialogsFileBrowserOptions* options) {
FuriApiLock lock = API_LOCK_INIT_LOCKED();
furi_check(lock != NULL);
@@ -2,7 +2,6 @@
#include <furi.h>
#include "dialogs_i.h"
#include "dialogs_api_lock.h"
#include "m-string.h"
#ifdef __cplusplus
extern "C" {
@@ -13,8 +12,8 @@ typedef struct {
bool skip_assets;
bool hide_ext;
const Icon* file_icon;
string_ptr result_path;
string_ptr preselected_filename;
FuriString* result_path;
FuriString* preselected_filename;
FileBrowserLoadItemCallback item_callback;
void* item_callback_context;
} DialogsAppMessageDataFileBrowser;
+22 -23
View File
@@ -8,7 +8,6 @@
#include <gui/icon_i.h>
#include <gui/icon_animation_i.h>
#include <m-string.h>
#include <furi.h>
#include "canvas_i.h"
@@ -189,12 +188,12 @@ static size_t
end = text + strlen(text);
}
size_t text_size = end - text;
string_t str;
string_init_set_str(str, text);
string_left(str, text_size);
FuriString* str;
str = furi_string_alloc_set(text);
furi_string_left(str, text_size);
size_t result = 0;
uint16_t len_px = canvas_string_width(canvas, string_get_cstr(str));
uint16_t len_px = canvas_string_width(canvas, furi_string_get_cstr(str));
uint8_t px_left = 0;
if(horizontal == AlignCenter) {
if(x > (canvas_width(canvas) / 2)) {
@@ -224,7 +223,7 @@ static size_t
result = text_size;
}
string_clear(str);
furi_string_free(str);
return result;
}
@@ -240,7 +239,7 @@ void elements_multiline_text_aligned(
uint8_t lines_count = 0;
uint8_t font_height = canvas_current_font_height(canvas);
string_t line;
FuriString* line;
/* go through text line by line and count lines */
for(const char* start = text; start[0];) {
@@ -261,14 +260,14 @@ void elements_multiline_text_aligned(
size_t chars_fit = elements_get_max_chars_to_fit(canvas, horizontal, start, x);
if((start[chars_fit] == '\n') || (start[chars_fit] == 0)) {
string_init_printf(line, "%.*s", chars_fit, start);
line = furi_string_alloc_printf("%.*s", chars_fit, start);
} else if((y + font_height) > canvas_height(canvas)) {
string_init_printf(line, "%.*s...\n", chars_fit, start);
line = furi_string_alloc_printf("%.*s...\n", chars_fit, start);
} else {
string_init_printf(line, "%.*s-\n", chars_fit, start);
line = furi_string_alloc_printf("%.*s-\n", chars_fit, start);
}
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(line));
string_clear(line);
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, furi_string_get_cstr(line));
furi_string_free(line);
y += font_height;
if(y > canvas_height(canvas)) {
break;
@@ -284,22 +283,22 @@ void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* t
furi_assert(text);
uint8_t font_height = canvas_current_font_height(canvas);
string_t str;
string_init(str);
FuriString* str;
str = furi_string_alloc();
const char* start = text;
char* end;
do {
end = strchr(start, '\n');
if(end) {
string_set_strn(str, start, end - start);
furi_string_set_strn(str, start, end - start);
} else {
string_set_str(str, start);
furi_string_set(str, start);
}
canvas_draw_str(canvas, x, y, string_get_cstr(str));
canvas_draw_str(canvas, x, y, furi_string_get_cstr(str));
start = end + 1;
y += font_height;
} while(end && y < 64);
string_clear(str);
furi_string_free(str);
}
void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text) {
@@ -533,18 +532,18 @@ void elements_bubble_str(
canvas_draw_line(canvas, x2, y2, x3, y3);
}
void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) {
void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width) {
furi_assert(canvas);
furi_assert(string);
uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string));
uint16_t len_px = canvas_string_width(canvas, furi_string_get_cstr(string));
if(len_px > width) {
width -= canvas_string_width(canvas, "...");
do {
string_left(string, string_size(string) - 1);
len_px = canvas_string_width(canvas, string_get_cstr(string));
furi_string_left(string, furi_string_size(string) - 1);
len_px = canvas_string_width(canvas, furi_string_get_cstr(string));
} while(len_px > width);
string_cat(string, "...");
furi_string_cat(string, "...");
}
}
+2 -2
View File
@@ -9,7 +9,7 @@
#pragma once
#include <stdint.h>
#include <m-string.h>
#include <furi.h>
#include "canvas.h"
#ifdef __cplusplus
@@ -190,7 +190,7 @@ void elements_bubble_str(
* @param string string to trim
* @param width max width
*/
void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width);
void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width);
/** Draw text box element
*
@@ -79,8 +79,8 @@ static void button_menu_draw_common_button(
canvas_draw_rframe(canvas, item_x, item_y, ITEM_WIDTH, ITEM_HEIGHT, 5);
}
string_t disp_str;
string_init_set_str(disp_str, text);
FuriString* disp_str;
disp_str = furi_string_alloc_set(text);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(
@@ -89,9 +89,9 @@ static void button_menu_draw_common_button(
item_y + (ITEM_HEIGHT / 2),
AlignCenter,
AlignCenter,
string_get_cstr(disp_str));
furi_string_get_cstr(disp_str));
string_clear(disp_str);
furi_string_free(disp_str);
}
static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
@@ -116,12 +116,12 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
}
if(model->header) {
string_t disp_str;
string_init_set_str(disp_str, model->header);
FuriString* disp_str;
disp_str = furi_string_alloc_set(model->header);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(
canvas, 32, 10, AlignCenter, AlignCenter, string_get_cstr(disp_str));
string_clear(disp_str);
canvas, 32, 10, AlignCenter, AlignCenter, furi_string_get_cstr(disp_str));
furi_string_free(disp_str);
}
for(ButtonMenuItemArray_it(it, model->items); !ButtonMenuItemArray_end_p(it);
@@ -5,7 +5,6 @@
#include <core/common_defines.h>
#include <core/log.h>
#include "furi_hal_resources.h"
#include "m-string.h"
#include <m-array.h>
#include <gui/elements.h>
#include <furi.h>
@@ -28,23 +27,23 @@ typedef enum {
} BrowserItemType;
typedef struct {
string_t path;
FuriString* path;
BrowserItemType type;
uint8_t* custom_icon_data;
string_t display_name;
FuriString* display_name;
} BrowserItem_t;
static void BrowserItem_t_init(BrowserItem_t* obj) {
obj->type = BrowserItemTypeLoading;
string_init(obj->path);
string_init(obj->display_name);
obj->path = furi_string_alloc();
obj->display_name = furi_string_alloc();
obj->custom_icon_data = NULL;
}
static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->type = src->type;
string_init_set(obj->path, src->path);
string_init_set(obj->display_name, src->display_name);
obj->path = furi_string_alloc_set(src->path);
obj->display_name = furi_string_alloc_set(src->display_name);
if(src->custom_icon_data) {
obj->custom_icon_data = malloc(CUSTOM_ICON_MAX_SIZE);
memcpy(obj->custom_icon_data, src->custom_icon_data, CUSTOM_ICON_MAX_SIZE);
@@ -55,8 +54,8 @@ static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src)
static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->type = src->type;
string_set(obj->path, src->path);
string_set(obj->display_name, src->display_name);
furi_string_set(obj->path, src->path);
furi_string_set(obj->display_name, src->display_name);
if(src->custom_icon_data) {
obj->custom_icon_data = malloc(CUSTOM_ICON_MAX_SIZE);
memcpy(obj->custom_icon_data, src->custom_icon_data, CUSTOM_ICON_MAX_SIZE);
@@ -66,8 +65,8 @@ static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
}
static void BrowserItem_t_clear(BrowserItem_t* obj) {
string_clear(obj->path);
string_clear(obj->display_name);
furi_string_free(obj->path);
furi_string_free(obj->display_name);
if(obj->custom_icon_data) {
free(obj->custom_icon_data);
}
@@ -94,7 +93,7 @@ struct FileBrowser {
FileBrowserLoadItemCallback item_callback;
void* item_context;
string_ptr result_path;
FuriString* result_path;
};
typedef struct {
@@ -125,10 +124,11 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context);
static void
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
static void browser_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last);
static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last);
static void browser_long_load_cb(void* context);
FileBrowser* file_browser_alloc(string_ptr result_path) {
FileBrowser* file_browser_alloc(FuriString* result_path) {
furi_assert(result_path);
FileBrowser* browser = malloc(sizeof(FileBrowser));
browser->view = view_alloc();
@@ -186,7 +186,7 @@ void file_browser_configure(
});
}
void file_browser_start(FileBrowser* browser, string_t path) {
void file_browser_start(FileBrowser* browser, FuriString* path) {
furi_assert(browser);
browser->worker = file_browser_worker_alloc(path, browser->ext_filter, browser->skip_assets);
file_browser_worker_set_callback_context(browser->worker, browser);
@@ -336,7 +336,8 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
BrowserItem_t_clear(&back_item);
}
static void browser_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last) {
static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
furi_assert(context);
FileBrowser* browser = (FileBrowser*)context;
@@ -344,8 +345,8 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
item.custom_icon_data = NULL;
if(!is_last) {
string_init_set(item.path, item_path);
string_init(item.display_name);
item.path = furi_string_alloc_set(item_path);
item.display_name = furi_string_alloc();
if(is_folder) {
item.type = BrowserItemTypeFolder;
} else {
@@ -363,7 +364,7 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
}
}
if(string_empty_p(item.display_name)) {
if(furi_string_empty(item.display_name)) {
path_extract_filename(
item_path,
item.display_name,
@@ -376,8 +377,8 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
// TODO: calculate if element is visible
return true;
});
string_clear(item.display_name);
string_clear(item.path);
furi_string_free(item.display_name);
furi_string_free(item.path);
} else {
with_view_model(
browser->view, (FileBrowserModel * model) {
@@ -427,8 +428,8 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
uint32_t array_size = items_array_size(model->items);
bool show_scrollbar = model->item_cnt > LIST_ITEMS;
string_t filename;
string_init(filename);
FuriString* filename;
filename = furi_string_alloc();
for(uint32_t i = 0; i < MIN(model->item_cnt, LIST_ITEMS); i++) {
int32_t idx = CLAMP((uint32_t)(i + model->list_offset), model->item_cnt, 0u);
@@ -440,16 +441,16 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
BrowserItem_t* item = items_array_get(
model->items, CLAMP(idx - model->array_offset, (int32_t)(array_size - 1), 0));
item_type = item->type;
string_set(filename, item->display_name);
furi_string_set(filename, item->display_name);
if(item_type == BrowserItemTypeFile) {
custom_icon_data = item->custom_icon_data;
}
} else {
string_set_str(filename, "---");
furi_string_set(filename, "---");
}
if(item_type == BrowserItemTypeBack) {
string_set_str(filename, ". .");
furi_string_set(filename, ". .");
}
elements_string_fit_width(
@@ -471,7 +472,8 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
canvas_draw_icon(
canvas, 2, Y_OFFSET + 1 + i * FRAME_HEIGHT, BrowserItemIcons[item_type]);
}
canvas_draw_str(canvas, 15, Y_OFFSET + 9 + i * FRAME_HEIGHT, string_get_cstr(filename));
canvas_draw_str(
canvas, 15, Y_OFFSET + 9 + i * FRAME_HEIGHT, furi_string_get_cstr(filename));
}
if(show_scrollbar) {
@@ -484,7 +486,7 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
model->item_cnt);
}
string_clear(filename);
furi_string_free(filename);
}
static void file_browser_view_draw_callback(Canvas* canvas, void* _model) {
@@ -568,7 +570,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
file_browser_worker_folder_enter(
browser->worker, selected_item->path, select_index);
} else if(selected_item->type == BrowserItemTypeFile) {
string_set(browser->result_path, selected_item->path);
furi_string_set(browser->result_path, selected_item->path);
if(browser->callback) {
browser->callback(browser->context);
}
@@ -5,7 +5,6 @@
#pragma once
#include "m-string.h"
#include <gui/view.h>
#ifdef __cplusplus
@@ -15,10 +14,13 @@ extern "C" {
typedef struct FileBrowser FileBrowser;
typedef void (*FileBrowserCallback)(void* context);
typedef bool (
*FileBrowserLoadItemCallback)(string_t path, void* context, uint8_t** icon, string_t item_name);
typedef bool (*FileBrowserLoadItemCallback)(
FuriString* path,
void* context,
uint8_t** icon,
FuriString* item_name);
FileBrowser* file_browser_alloc(string_ptr result_path);
FileBrowser* file_browser_alloc(FuriString* result_path);
void file_browser_free(FileBrowser* browser);
@@ -31,7 +33,7 @@ void file_browser_configure(
const Icon* file_icon,
bool hide_ext);
void file_browser_start(FileBrowser* browser, string_t path);
void file_browser_start(FileBrowser* browser, FuriString* path);
void file_browser_stop(FileBrowser* browser);
@@ -1,7 +1,6 @@
#include "file_browser_worker.h"
#include <core/check.h>
#include <core/common_defines.h>
#include "m-string.h"
#include "storage/filesystem_api_defines.h"
#include <m-array.h>
#include <stdbool.h>
@@ -35,8 +34,8 @@ ARRAY_DEF(idx_last_array, int32_t)
struct BrowserWorker {
FuriThread* thread;
string_t filter_extension;
string_t path_next;
FuriString* filter_extension;
FuriString* path_next;
int32_t item_sel_idx;
uint32_t load_offset;
uint32_t load_count;
@@ -50,11 +49,11 @@ struct BrowserWorker {
BrowserWorkerLongLoadCallback long_load_cb;
};
static bool browser_path_is_file(string_t path) {
static bool browser_path_is_file(FuriString* path) {
bool state = false;
FileInfo file_info;
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
if((file_info.flags & FSF_DIRECTORY) == 0) {
state = true;
}
@@ -63,50 +62,50 @@ static bool browser_path_is_file(string_t path) {
return state;
}
static bool browser_path_trim(string_t path) {
static bool browser_path_trim(FuriString* path) {
bool is_root = false;
size_t filename_start = string_search_rchar(path, '/');
string_left(path, filename_start);
if((string_empty_p(path)) || (filename_start == STRING_FAILURE)) {
string_set_str(path, BROWSER_ROOT);
size_t filename_start = furi_string_search_rchar(path, '/');
furi_string_left(path, filename_start);
if((furi_string_empty(path)) || (filename_start == FURI_STRING_FAILURE)) {
furi_string_set(path, BROWSER_ROOT);
is_root = true;
}
return is_root;
}
static bool browser_filter_by_name(BrowserWorker* browser, string_t name, bool is_folder) {
static bool browser_filter_by_name(BrowserWorker* browser, FuriString* name, bool is_folder) {
if(is_folder) {
// Skip assets folders (if enabled)
if(browser->skip_assets) {
return ((string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true));
return ((furi_string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true));
} else {
return true;
}
} else {
// Filter files by extension
if((string_empty_p(browser->filter_extension)) ||
(string_cmp_str(browser->filter_extension, "*") == 0)) {
if((furi_string_empty(browser->filter_extension)) ||
(furi_string_cmp_str(browser->filter_extension, "*") == 0)) {
return true;
}
if(string_end_with_string_p(name, browser->filter_extension)) {
if(furi_string_end_with(name, browser->filter_extension)) {
return true;
}
}
return false;
}
static bool browser_folder_check_and_switch(string_t path) {
static bool browser_folder_check_and_switch(FuriString* path) {
FileInfo file_info;
Storage* storage = furi_record_open(RECORD_STORAGE);
bool is_root = false;
if(string_search_rchar(path, '/') == 0) {
if(furi_string_search_rchar(path, '/') == 0) {
is_root = true;
}
while(1) {
// Check if folder is existing and navigate back if not
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
if(file_info.flags & FSF_DIRECTORY) {
break;
}
@@ -122,8 +121,8 @@ static bool browser_folder_check_and_switch(string_t path) {
static bool browser_folder_init(
BrowserWorker* browser,
string_t path,
string_t filename,
FuriString* path,
FuriString* filename,
uint32_t* item_cnt,
int32_t* file_idx) {
bool state = false;
@@ -134,13 +133,13 @@ static bool browser_folder_init(
File* directory = storage_file_alloc(storage);
char name_temp[FILE_NAME_LEN_MAX];
string_t name_str;
string_init(name_str);
FuriString* name_str;
name_str = furi_string_alloc();
*item_cnt = 0;
*file_idx = -1;
if(storage_dir_open(directory, string_get_cstr(path))) {
if(storage_dir_open(directory, furi_string_get_cstr(path))) {
state = true;
while(1) {
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
@@ -148,10 +147,10 @@ static bool browser_folder_init(
}
if((storage_file_get_error(directory) == FSE_OK) && (name_temp[0] != '\0')) {
total_files_cnt++;
string_set_str(name_str, name_temp);
furi_string_set(name_str, name_temp);
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
if(!string_empty_p(filename)) {
if(string_cmp(name_str, filename) == 0) {
if(!furi_string_empty(filename)) {
if(furi_string_cmp(name_str, filename) == 0) {
*file_idx = *item_cnt;
}
}
@@ -167,7 +166,7 @@ static bool browser_folder_init(
}
}
string_clear(name_str);
furi_string_free(name_str);
storage_dir_close(directory);
storage_file_free(directory);
@@ -178,20 +177,20 @@ static bool browser_folder_init(
}
static bool
browser_folder_load(BrowserWorker* browser, string_t path, uint32_t offset, uint32_t count) {
browser_folder_load(BrowserWorker* browser, FuriString* path, uint32_t offset, uint32_t count) {
FileInfo file_info;
Storage* storage = furi_record_open(RECORD_STORAGE);
File* directory = storage_file_alloc(storage);
char name_temp[FILE_NAME_LEN_MAX];
string_t name_str;
string_init(name_str);
FuriString* name_str;
name_str = furi_string_alloc();
uint32_t items_cnt = 0;
do {
if(!storage_dir_open(directory, string_get_cstr(path))) {
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
break;
}
@@ -201,7 +200,7 @@ static bool
break;
}
if(storage_file_get_error(directory) == FSE_OK) {
string_set_str(name_str, name_temp);
furi_string_set(name_str, name_temp);
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
items_cnt++;
}
@@ -223,9 +222,9 @@ static bool
break;
}
if(storage_file_get_error(directory) == FSE_OK) {
string_set_str(name_str, name_temp);
furi_string_set(name_str, name_temp);
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
string_printf(name_str, "%s/%s", string_get_cstr(path), name_temp);
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
if(browser->list_item_cb) {
browser->list_item_cb(
browser->cb_ctx, name_str, (file_info.flags & FSF_DIRECTORY), false);
@@ -241,7 +240,7 @@ static bool
}
} while(0);
string_clear(name_str);
furi_string_free(name_str);
storage_dir_close(directory);
storage_file_free(directory);
@@ -257,12 +256,12 @@ static int32_t browser_worker(void* context) {
FURI_LOG_D(TAG, "Start");
uint32_t items_cnt = 0;
string_t path;
string_init_set_str(path, BROWSER_ROOT);
FuriString* path;
path = furi_string_alloc_set(BROWSER_ROOT);
browser->item_sel_idx = -1;
string_t filename;
string_init(filename);
FuriString* filename;
filename = furi_string_alloc();
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
@@ -282,7 +281,7 @@ static int32_t browser_worker(void* context) {
}
if(flags & WorkerEvtFolderEnter) {
string_set(path, browser->path_next);
furi_string_set(path, browser->path_next);
bool is_root = browser_folder_check_and_switch(path);
// Push previous selected item index to history array
@@ -293,13 +292,13 @@ static int32_t browser_worker(void* context) {
FURI_LOG_D(
TAG,
"Enter folder: %s items: %u idx: %d",
string_get_cstr(path),
furi_string_get_cstr(path),
items_cnt,
file_idx);
if(browser->folder_cb) {
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
}
string_reset(filename);
furi_string_reset(filename);
}
if(flags & WorkerEvtFolderExit) {
@@ -313,7 +312,11 @@ static int32_t browser_worker(void* context) {
idx_last_array_pop_back(&file_idx, browser->idx_last);
}
FURI_LOG_D(
TAG, "Exit to: %s items: %u idx: %d", string_get_cstr(path), items_cnt, file_idx);
TAG,
"Exit to: %s items: %u idx: %d",
furi_string_get_cstr(path),
items_cnt,
file_idx);
if(browser->folder_cb) {
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
}
@@ -323,12 +326,12 @@ static int32_t browser_worker(void* context) {
bool is_root = browser_folder_check_and_switch(path);
int32_t file_idx = 0;
string_reset(filename);
furi_string_reset(filename);
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
FURI_LOG_D(
TAG,
"Refresh folder: %s items: %u idx: %d",
string_get_cstr(path),
furi_string_get_cstr(path),
items_cnt,
browser->item_sel_idx);
if(browser->folder_cb) {
@@ -346,21 +349,22 @@ static int32_t browser_worker(void* context) {
}
}
string_clear(filename);
string_clear(path);
furi_string_free(filename);
furi_string_free(path);
FURI_LOG_D(TAG, "End");
return 0;
}
BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets) {
BrowserWorker*
file_browser_worker_alloc(FuriString* path, const char* filter_ext, bool skip_assets) {
BrowserWorker* browser = malloc(sizeof(BrowserWorker));
idx_last_array_init(browser->idx_last);
string_init_set_str(browser->filter_extension, filter_ext);
browser->filter_extension = furi_string_alloc_set(filter_ext);
browser->skip_assets = skip_assets;
string_init_set(browser->path_next, path);
browser->path_next = furi_string_alloc_set(path);
browser->thread = furi_thread_alloc();
furi_thread_set_name(browser->thread, "BrowserWorker");
@@ -379,8 +383,8 @@ void file_browser_worker_free(BrowserWorker* browser) {
furi_thread_join(browser->thread);
furi_thread_free(browser->thread);
string_clear(browser->filter_extension);
string_clear(browser->path_next);
furi_string_free(browser->filter_extension);
furi_string_free(browser->path_next);
idx_last_array_clear(browser->idx_last);
@@ -422,19 +426,19 @@ void file_browser_worker_set_long_load_callback(
void file_browser_worker_set_config(
BrowserWorker* browser,
string_t path,
FuriString* path,
const char* filter_ext,
bool skip_assets) {
furi_assert(browser);
string_set(browser->path_next, path);
string_set_str(browser->filter_extension, filter_ext);
furi_string_set(browser->path_next, path);
furi_string_set(browser->filter_extension, filter_ext);
browser->skip_assets = skip_assets;
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
}
void file_browser_worker_folder_enter(BrowserWorker* browser, string_t path, int32_t item_idx) {
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx) {
furi_assert(browser);
string_set(browser->path_next, path);
furi_string_set(browser->path_next, path);
browser->item_sel_idx = item_idx;
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
}
@@ -1,6 +1,5 @@
#pragma once
#include "m-string.h"
#include <gui/view.h>
#include <stdint.h>
@@ -17,12 +16,13 @@ typedef void (*BrowserWorkerFolderOpenCallback)(
typedef void (*BrowserWorkerListLoadCallback)(void* context, uint32_t list_load_offset);
typedef void (*BrowserWorkerListItemCallback)(
void* context,
string_t item_path,
FuriString* item_path,
bool is_folder,
bool is_last);
typedef void (*BrowserWorkerLongLoadCallback)(void* context);
BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets);
BrowserWorker*
file_browser_worker_alloc(FuriString* path, const char* filter_ext, bool skip_assets);
void file_browser_worker_free(BrowserWorker* browser);
@@ -46,11 +46,11 @@ void file_browser_worker_set_long_load_callback(
void file_browser_worker_set_config(
BrowserWorker* browser,
string_t path,
FuriString* path,
const char* filter_ext,
bool skip_assets);
void file_browser_worker_folder_enter(BrowserWorker* browser, string_t path, int32_t item_idx);
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx);
void file_browser_worker_folder_exit(BrowserWorker* browser);
+4 -4
View File
@@ -65,17 +65,17 @@ static void submenu_view_draw_callback(Canvas* canvas, void* _model) {
canvas_set_color(canvas, ColorBlack);
}
string_t disp_str;
string_init_set_str(disp_str, SubmenuItemArray_cref(it)->label);
FuriString* disp_str;
disp_str = furi_string_alloc_set(SubmenuItemArray_cref(it)->label);
elements_string_fit_width(canvas, disp_str, item_width - 20);
canvas_draw_str(
canvas,
6,
y_offset + (item_position * item_height) + item_height - 4,
string_get_cstr(disp_str));
furi_string_get_cstr(disp_str));
string_clear(disp_str);
furi_string_free(disp_str);
}
position++;
+9 -10
View File
@@ -1,6 +1,5 @@
#include "text_box.h"
#include "gui/canvas.h"
#include <m-string.h>
#include <furi.h>
#include <gui/elements.h>
#include <stdint.h>
@@ -12,7 +11,7 @@ struct TextBox {
typedef struct {
const char* text;
char* text_pos;
string_t text_formatted;
FuriString* text_formatted;
int32_t scroll_pos;
int32_t scroll_num;
TextBoxFont font;
@@ -66,17 +65,17 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
if(line_width + glyph_width > text_width) {
line_num++;
line_width = 0;
string_push_back(model->text_formatted, '\n');
furi_string_push_back(model->text_formatted, '\n');
}
line_width += glyph_width;
} else {
line_num++;
line_width = 0;
}
string_push_back(model->text_formatted, symb);
furi_string_push_back(model->text_formatted, symb);
}
line_num++;
model->text = string_get_cstr(model->text_formatted);
model->text = furi_string_get_cstr(model->text_formatted);
model->text_pos = (char*)model->text;
if(model->focus == TextBoxFocusEnd && line_num > 5) {
// Set text position to 5th line from the end
@@ -140,7 +139,7 @@ TextBox* text_box_alloc() {
with_view_model(
text_box->view, (TextBoxModel * model) {
model->text = NULL;
string_init_set_str(model->text_formatted, "");
model->text_formatted = furi_string_alloc_set("");
model->formatted = false;
model->font = TextBoxFontText;
return true;
@@ -154,7 +153,7 @@ void text_box_free(TextBox* text_box) {
with_view_model(
text_box->view, (TextBoxModel * model) {
string_clear(model->text_formatted);
furi_string_free(model->text_formatted);
return true;
});
view_free(text_box->view);
@@ -172,7 +171,7 @@ void text_box_reset(TextBox* text_box) {
with_view_model(
text_box->view, (TextBoxModel * model) {
model->text = NULL;
string_set_str(model->text_formatted, "");
furi_string_set(model->text_formatted, "");
model->font = TextBoxFontText;
model->focus = TextBoxFocusStart;
return true;
@@ -186,8 +185,8 @@ void text_box_set_text(TextBox* text_box, const char* text) {
with_view_model(
text_box->view, (TextBoxModel * model) {
model->text = text;
string_reset(model->text_formatted);
string_reserve(model->text_formatted, strlen(text));
furi_string_reset(model->text_formatted);
furi_string_reserve(model->text_formatted, strlen(text));
model->formatted = false;
return true;
});
@@ -27,7 +27,7 @@ typedef struct {
TextInputValidatorCallback validator_callback;
void* validator_callback_context;
string_t validator_text;
FuriString* validator_text;
bool valadator_message_visible;
} TextInputModel;
@@ -257,7 +257,7 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
elements_multiline_text(canvas, 62, 20, string_get_cstr(model->validator_text));
elements_multiline_text(canvas, 62, 20, furi_string_get_cstr(model->validator_text));
canvas_set_font(canvas, FontKeyboard);
}
}
@@ -447,7 +447,7 @@ TextInput* text_input_alloc() {
with_view_model(
text_input->view, (TextInputModel * model) {
string_init(model->validator_text);
model->validator_text = furi_string_alloc();
return false;
});
@@ -460,7 +460,7 @@ void text_input_free(TextInput* text_input) {
furi_assert(text_input);
with_view_model(
text_input->view, (TextInputModel * model) {
string_clear(model->validator_text);
furi_string_free(model->validator_text);
return false;
});
@@ -489,7 +489,7 @@ void text_input_reset(TextInput* text_input) {
model->callback_context = NULL;
model->validator_callback = NULL;
model->validator_callback_context = NULL;
string_reset(model->validator_text);
furi_string_reset(model->validator_text);
model->valadator_message_visible = false;
return true;
});
@@ -7,7 +7,6 @@
#include <gui/view.h>
#include "validators.h"
#include <m-string.h>
#ifdef __cplusplus
extern "C" {
@@ -16,7 +15,7 @@ extern "C" {
/** Text input anonymous structure */
typedef struct TextInput TextInput;
typedef void (*TextInputCallback)(void* context);
typedef bool (*TextInputValidatorCallback)(const char* text, string_t error, void* context);
typedef bool (*TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
/** Allocate and initialize text input
*
@@ -8,7 +8,7 @@ struct ValidatorIsFile {
char* current_name;
};
bool validator_is_file_callback(const char* text, string_t error, void* context) {
bool validator_is_file_callback(const char* text, FuriString* error, void* context) {
furi_assert(context);
ValidatorIsFile* instance = context;
@@ -19,16 +19,16 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
}
bool ret = true;
string_t path;
string_init_printf(path, "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
FuriString* path = furi_string_alloc_printf(
"%s/%s%s", instance->app_path_folder, text, instance->app_extension);
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_common_stat(storage, string_get_cstr(path), NULL) == FSE_OK) {
if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) {
ret = false;
string_printf(error, "This name\nexists!\nChoose\nanother one.");
furi_string_printf(error, "This name\nexists!\nChoose\nanother one.");
} else {
ret = true;
}
string_clear(path);
furi_string_free(path);
furi_record_close(RECORD_STORAGE);
return ret;
@@ -1,6 +1,5 @@
#pragma once
#include <m-string.h>
#include <core/common_defines.h>
#ifdef __cplusplus
@@ -15,7 +14,7 @@ ValidatorIsFile* validator_is_file_alloc_init(
void validator_is_file_free(ValidatorIsFile* instance);
bool validator_is_file_callback(const char* text, string_t error, void* context);
bool validator_is_file_callback(const char* text, FuriString* error, void* context);
#ifdef __cplusplus
}
@@ -8,7 +8,7 @@
struct VariableItem {
const char* label;
uint8_t current_value_index;
string_t current_value_text;
FuriString* current_value_text;
uint8_t values_count;
VariableItemChangeCallback change_callback;
void* context;
@@ -77,7 +77,7 @@ static void variable_item_list_draw_callback(Canvas* canvas, void* _model) {
item_text_y,
AlignCenter,
AlignBottom,
string_get_cstr(item->current_value_text));
furi_string_get_cstr(item->current_value_text));
if(item->current_value_index < (item->values_count - 1)) {
canvas_draw_str(canvas, 115, item_text_y, ">");
@@ -303,7 +303,7 @@ void variable_item_list_free(VariableItemList* variable_item_list) {
VariableItemArray_it_t it;
for(VariableItemArray_it(it, model->items); !VariableItemArray_end_p(it);
VariableItemArray_next(it)) {
string_clear(VariableItemArray_ref(it)->current_value_text);
furi_string_free(VariableItemArray_ref(it)->current_value_text);
}
VariableItemArray_clear(model->items);
return false;
@@ -320,7 +320,7 @@ void variable_item_list_reset(VariableItemList* variable_item_list) {
VariableItemArray_it_t it;
for(VariableItemArray_it(it, model->items); !VariableItemArray_end_p(it);
VariableItemArray_next(it)) {
string_clear(VariableItemArray_ref(it)->current_value_text);
furi_string_free(VariableItemArray_ref(it)->current_value_text);
}
VariableItemArray_reset(model->items);
return false;
@@ -350,7 +350,7 @@ VariableItem* variable_item_list_add(
item->change_callback = change_callback;
item->context = context;
item->current_value_index = 0;
string_init(item->current_value_text);
item->current_value_text = furi_string_alloc();
return true;
});
@@ -376,7 +376,7 @@ void variable_item_set_current_value_index(VariableItem* item, uint8_t current_v
}
void variable_item_set_current_value_text(VariableItem* item, const char* current_value_text) {
string_set_str(item->current_value_text, current_value_text);
furi_string_set(item->current_value_text, current_value_text);
}
uint8_t variable_item_get_current_value_index(VariableItem* item) {
@@ -1,10 +1,9 @@
#include "widget_element_i.h"
#include <gui/elements.h>
#include <m-string.h>
typedef struct {
GuiButtonType button_type;
string_t text;
FuriString* text;
ButtonCallback callback;
void* context;
} GuiButtonModel;
@@ -18,11 +17,11 @@ static void gui_button_draw(Canvas* canvas, WidgetElement* element) {
canvas_set_font(canvas, FontSecondary);
if(model->button_type == GuiButtonTypeLeft) {
elements_button_left(canvas, string_get_cstr(model->text));
elements_button_left(canvas, furi_string_get_cstr(model->text));
} else if(model->button_type == GuiButtonTypeRight) {
elements_button_right(canvas, string_get_cstr(model->text));
elements_button_right(canvas, furi_string_get_cstr(model->text));
} else if(model->button_type == GuiButtonTypeCenter) {
elements_button_center(canvas, string_get_cstr(model->text));
elements_button_center(canvas, furi_string_get_cstr(model->text));
}
}
@@ -50,7 +49,7 @@ static void gui_button_free(WidgetElement* gui_button) {
furi_assert(gui_button);
GuiButtonModel* model = gui_button->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_button->model);
free(gui_button);
}
@@ -65,7 +64,7 @@ WidgetElement* widget_element_button_create(
model->button_type = button_type;
model->callback = callback;
model->context = context;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_button = malloc(sizeof(WidgetElement));
@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
typedef struct {
uint8_t x;
@@ -7,7 +6,7 @@ typedef struct {
Align horizontal;
Align vertical;
Font font;
string_t text;
FuriString* text;
} GuiStringModel;
static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
@@ -15,7 +14,7 @@ static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiStringModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
canvas_set_font(canvas, model->font);
canvas_draw_str_aligned(
canvas,
@@ -23,7 +22,7 @@ static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
model->y,
model->horizontal,
model->vertical,
string_get_cstr(model->text));
furi_string_get_cstr(model->text));
}
}
@@ -31,7 +30,7 @@ static void gui_string_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiStringModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -52,7 +51,7 @@ WidgetElement* widget_element_string_create(
model->horizontal = horizontal;
model->vertical = vertical;
model->font = font;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
typedef struct {
@@ -8,7 +7,7 @@ typedef struct {
Align horizontal;
Align vertical;
Font font;
string_t text;
FuriString* text;
} GuiStringMultiLineModel;
static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
@@ -16,7 +15,7 @@ static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiStringMultiLineModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
canvas_set_font(canvas, model->font);
elements_multiline_text_aligned(
canvas,
@@ -24,7 +23,7 @@ static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
model->y,
model->horizontal,
model->vertical,
string_get_cstr(model->text));
furi_string_get_cstr(model->text));
}
}
@@ -32,7 +31,7 @@ static void gui_string_multiline_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiStringMultiLineModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -53,7 +52,7 @@ WidgetElement* widget_element_string_multiline_create(
model->horizontal = horizontal;
model->vertical = vertical;
model->font = font;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
typedef struct {
@@ -9,7 +8,7 @@ typedef struct {
uint8_t height;
Align horizontal;
Align vertical;
string_t text;
FuriString* text;
bool strip_to_dots;
} GuiTextBoxModel;
@@ -18,7 +17,7 @@ static void gui_text_box_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiTextBoxModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
elements_text_box(
canvas,
model->x,
@@ -27,7 +26,7 @@ static void gui_text_box_draw(Canvas* canvas, WidgetElement* element) {
model->height,
model->horizontal,
model->vertical,
string_get_cstr(model->text),
furi_string_get_cstr(model->text),
model->strip_to_dots);
}
}
@@ -36,7 +35,7 @@ static void gui_text_box_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiTextBoxModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -60,7 +59,7 @@ WidgetElement* widget_element_text_box_create(
model->height = height;
model->horizontal = horizontal;
model->vertical = vertical;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
model->strip_to_dots = strip_to_dots;
// Allocate and init Element
@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
#include <m-array.h>
@@ -8,7 +7,7 @@
typedef struct {
Font font;
Align horizontal;
string_t text;
FuriString* text;
} TextScrollLineArray;
ARRAY_DEF(TextScrollLineArray, TextScrollLineArray, M_POD_OPLIST)
@@ -19,19 +18,19 @@ typedef struct {
uint8_t y;
uint8_t width;
uint8_t height;
string_t text;
FuriString* text;
uint8_t scroll_pos_total;
uint8_t scroll_pos_current;
bool text_formatted;
} WidgetElementTextScrollModel;
static bool
widget_element_text_scroll_process_ctrl_symbols(TextScrollLineArray* line, string_t text) {
widget_element_text_scroll_process_ctrl_symbols(TextScrollLineArray* line, FuriString* text) {
bool processed = false;
do {
if(string_get_char(text, 0) != '\e') break;
char ctrl_symbol = string_get_char(text, 1);
if(furi_string_get_char(text, 0) != '\e') break;
char ctrl_symbol = furi_string_get_char(text, 1);
if(ctrl_symbol == 'c') {
line->horizontal = AlignCenter;
} else if(ctrl_symbol == 'r') {
@@ -39,7 +38,7 @@ static bool
} else if(ctrl_symbol == '#') {
line->font = FontPrimary;
}
string_right(text, 2);
furi_string_right(text, 2);
processed = true;
} while(false);
@@ -51,7 +50,7 @@ void widget_element_text_scroll_add_line(WidgetElement* element, TextScrollLineA
TextScrollLineArray new_line;
new_line.font = line->font;
new_line.horizontal = line->horizontal;
string_init_set(new_line.text, line->text);
new_line.text = furi_string_alloc_set(line->text);
TextScrollLineArray_push_back(model->line_array, new_line);
}
@@ -59,7 +58,7 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
WidgetElementTextScrollModel* model = element->model;
TextScrollLineArray line_tmp;
bool all_text_processed = false;
string_init(line_tmp.text);
line_tmp.text = furi_string_alloc();
bool reached_new_line = true;
uint16_t total_height = 0;
@@ -68,7 +67,7 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
// Set default line properties
line_tmp.font = FontSecondary;
line_tmp.horizontal = AlignLeft;
string_reset(line_tmp.text);
furi_string_reset(line_tmp.text);
// Process control symbols
while(widget_element_text_scroll_process_ctrl_symbols(&line_tmp, model->text))
;
@@ -84,38 +83,38 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
uint8_t line_width = 0;
uint16_t char_i = 0;
while(true) {
char next_char = string_get_char(model->text, char_i++);
char next_char = furi_string_get_char(model->text, char_i++);
if(next_char == '\0') {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
total_height += params->leading_default - params->height;
all_text_processed = true;
break;
} else if(next_char == '\n') {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
string_right(model->text, char_i);
furi_string_right(model->text, char_i);
total_height += params->leading_default - params->height;
reached_new_line = true;
break;
} else {
line_width += canvas_glyph_width(canvas, next_char);
if(line_width > model->width) {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
string_right(model->text, char_i - 1);
string_reset(line_tmp.text);
furi_string_right(model->text, char_i - 1);
furi_string_reset(line_tmp.text);
total_height += params->leading_default - params->height;
reached_new_line = false;
break;
} else {
string_push_back(line_tmp.text, next_char);
furi_string_push_back(line_tmp.text, next_char);
}
}
}
}
string_clear(line_tmp.text);
furi_string_free(line_tmp.text);
}
static void widget_element_text_scroll_draw(Canvas* canvas, WidgetElement* element) {
@@ -150,7 +149,7 @@ static void widget_element_text_scroll_draw(Canvas* canvas, WidgetElement* eleme
x = model->x + model->width;
}
canvas_draw_str_aligned(
canvas, x, y, line->horizontal, AlignTop, string_get_cstr(line->text));
canvas, x, y, line->horizontal, AlignTop, furi_string_get_cstr(line->text));
y += params->leading_default;
}
// Draw scroll bar
@@ -205,10 +204,10 @@ static void widget_element_text_scroll_free(WidgetElement* text_scroll) {
for(TextScrollLineArray_it(it, model->line_array); !TextScrollLineArray_end_p(it);
TextScrollLineArray_next(it)) {
TextScrollLineArray* line = TextScrollLineArray_ref(it);
string_clear(line->text);
furi_string_free(line->text);
}
TextScrollLineArray_clear(model->line_array);
string_clear(model->text);
furi_string_free(model->text);
free(text_scroll->model);
furi_mutex_free(text_scroll->model_mutex);
free(text_scroll);
@@ -231,7 +230,7 @@ WidgetElement* widget_element_text_scroll_create(
model->scroll_pos_current = 0;
model->scroll_pos_total = 1;
TextScrollLineArray_init(model->line_array);
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
WidgetElement* text_scroll = malloc(sizeof(WidgetElement));
text_scroll->parent = NULL;
+21 -21
View File
@@ -19,7 +19,7 @@ static void input_cli_dump_events_callback(const void* value, void* ctx) {
furi_message_queue_put(input_queue, value, FuriWaitForever);
}
static void input_cli_dump(Cli* cli, string_t args, Input* input) {
static void input_cli_dump(Cli* cli, FuriString* args, Input* input) {
UNUSED(args);
FuriMessageQueue* input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
FuriPubSubSubscription* input_subscription =
@@ -47,11 +47,11 @@ static void input_cli_send_print_usage() {
printf("\t\t <type>\t - one of 'press', 'release', 'short', 'long'\r\n");
}
static void input_cli_send(Cli* cli, string_t args, Input* input) {
static void input_cli_send(Cli* cli, FuriString* args, Input* input) {
UNUSED(cli);
InputEvent event;
string_t key_str;
string_init(key_str);
FuriString* key_str;
key_str = furi_string_alloc();
bool parsed = false;
do {
@@ -59,29 +59,29 @@ static void input_cli_send(Cli* cli, string_t args, Input* input) {
if(!args_read_string_and_trim(args, key_str)) {
break;
}
if(!string_cmp(key_str, "up")) {
if(!furi_string_cmp(key_str, "up")) {
event.key = InputKeyUp;
} else if(!string_cmp(key_str, "down")) {
} else if(!furi_string_cmp(key_str, "down")) {
event.key = InputKeyDown;
} else if(!string_cmp(key_str, "left")) {
} else if(!furi_string_cmp(key_str, "left")) {
event.key = InputKeyLeft;
} else if(!string_cmp(key_str, "right")) {
} else if(!furi_string_cmp(key_str, "right")) {
event.key = InputKeyRight;
} else if(!string_cmp(key_str, "ok")) {
} else if(!furi_string_cmp(key_str, "ok")) {
event.key = InputKeyOk;
} else if(!string_cmp(key_str, "back")) {
} else if(!furi_string_cmp(key_str, "back")) {
event.key = InputKeyBack;
} else {
break;
}
// Parse Type
if(!string_cmp(args, "press")) {
if(!furi_string_cmp(args, "press")) {
event.type = InputTypePress;
} else if(!string_cmp(args, "release")) {
} else if(!furi_string_cmp(args, "release")) {
event.type = InputTypeRelease;
} else if(!string_cmp(args, "short")) {
} else if(!furi_string_cmp(args, "short")) {
event.type = InputTypeShort;
} else if(!string_cmp(args, "long")) {
} else if(!furi_string_cmp(args, "long")) {
event.type = InputTypeLong;
} else {
break;
@@ -94,26 +94,26 @@ static void input_cli_send(Cli* cli, string_t args, Input* input) {
} else {
input_cli_send_print_usage();
}
string_clear(key_str);
furi_string_free(key_str);
}
void input_cli(Cli* cli, string_t args, void* context) {
void input_cli(Cli* cli, FuriString* args, void* context) {
furi_assert(cli);
furi_assert(context);
Input* input = context;
string_t cmd;
string_init(cmd);
FuriString* cmd;
cmd = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
input_cli_usage();
break;
}
if(string_cmp_str(cmd, "dump") == 0) {
if(furi_string_cmp_str(cmd, "dump") == 0) {
input_cli_dump(cli, args, input);
break;
}
if(string_cmp_str(cmd, "send") == 0) {
if(furi_string_cmp_str(cmd, "send") == 0) {
input_cli_send(cli, args, input);
break;
}
@@ -121,5 +121,5 @@ void input_cli(Cli* cli, string_t args, void* context) {
input_cli_usage();
} while(false);
string_clear(cmd);
furi_string_free(cmd);
}
+1 -2
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <furi.h>
#include <cli/cli.h>
#include <m-string.h>
#include <furi_hal_gpio.h>
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
@@ -46,4 +45,4 @@ void input_press_timer_callback(void* arg);
void input_isr(void* _ctx);
/** Input CLI command handler */
void input_cli(Cli* cli, string_t args, void* context);
void input_cli(Cli* cli, FuriString* args, void* context);
+15 -15
View File
@@ -98,15 +98,15 @@ const FlipperApplication* loader_find_application_by_name(const char* name) {
return application;
}
void loader_cli_open(Cli* cli, string_t args, Loader* instance) {
void loader_cli_open(Cli* cli, FuriString* args, Loader* instance) {
UNUSED(cli);
if(loader_is_locked(instance)) {
printf("Can't start, furi application is running");
return;
}
string_t application_name;
string_init(application_name);
FuriString* application_name;
application_name = furi_string_alloc();
do {
if(!args_read_probably_quoted_string_and_trim(args, application_name)) {
@@ -115,14 +115,14 @@ void loader_cli_open(Cli* cli, string_t args, Loader* instance) {
}
const FlipperApplication* application =
loader_find_application_by_name(string_get_cstr(application_name));
loader_find_application_by_name(furi_string_get_cstr(application_name));
if(!application) {
printf("%s doesn't exists\r\n", string_get_cstr(application_name));
printf("%s doesn't exists\r\n", furi_string_get_cstr(application_name));
break;
}
string_strim(args);
if(!loader_start_application(application, string_get_cstr(args))) {
furi_string_trim(args);
if(!loader_start_application(application, furi_string_get_cstr(args))) {
printf("Can't start, furi application is running");
return;
} else {
@@ -134,10 +134,10 @@ void loader_cli_open(Cli* cli, string_t args, Loader* instance) {
}
} while(false);
string_clear(application_name);
furi_string_free(application_name);
}
void loader_cli_list(Cli* cli, string_t args, Loader* instance) {
void loader_cli_list(Cli* cli, FuriString* args, Loader* instance) {
UNUSED(cli);
UNUSED(args);
UNUSED(instance);
@@ -159,12 +159,12 @@ void loader_cli_list(Cli* cli, string_t args, Loader* instance) {
}
}
static void loader_cli(Cli* cli, string_t args, void* _ctx) {
static void loader_cli(Cli* cli, FuriString* args, void* _ctx) {
furi_assert(_ctx);
Loader* instance = _ctx;
string_t cmd;
string_init(cmd);
FuriString* cmd;
cmd = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
@@ -172,12 +172,12 @@ static void loader_cli(Cli* cli, string_t args, void* _ctx) {
break;
}
if(string_cmp_str(cmd, "list") == 0) {
if(furi_string_cmp_str(cmd, "list") == 0) {
loader_cli_list(cli, args, instance);
break;
}
if(string_cmp_str(cmd, "open") == 0) {
if(furi_string_cmp_str(cmd, "open") == 0) {
loader_cli_open(cli, args, instance);
break;
}
@@ -185,7 +185,7 @@ static void loader_cli(Cli* cli, string_t args, void* _ctx) {
loader_cli_print_usage();
} while(false);
string_clear(cmd);
furi_string_free(cmd);
}
LoaderStatus loader_start(Loader* instance, const char* name, const char* args) {
+24 -24
View File
@@ -5,7 +5,7 @@
#include <lib/toolbox/args.h>
#include <power/power_service/power.h>
void power_cli_off(Cli* cli, string_t args) {
void power_cli_off(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
Power* power = furi_record_open(RECORD_POWER);
@@ -14,13 +14,13 @@ void power_cli_off(Cli* cli, string_t args) {
power_off(power);
}
void power_cli_reboot(Cli* cli, string_t args) {
void power_cli_reboot(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
power_reboot(PowerBootModeNormal);
}
void power_cli_reboot2dfu(Cli* cli, string_t args) {
void power_cli_reboot2dfu(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
power_reboot(PowerBootModeDfu);
@@ -32,37 +32,37 @@ static void power_cli_info_callback(const char* key, const char* value, bool las
printf("%-24s: %s\r\n", key, value);
}
void power_cli_info(Cli* cli, string_t args) {
void power_cli_info(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
furi_hal_power_info_get(power_cli_info_callback, NULL);
}
void power_cli_debug(Cli* cli, string_t args) {
void power_cli_debug(Cli* cli, FuriString* args) {
UNUSED(cli);
UNUSED(args);
furi_hal_power_dump_state();
}
void power_cli_5v(Cli* cli, string_t args) {
void power_cli_5v(Cli* cli, FuriString* args) {
UNUSED(cli);
if(!string_cmp(args, "0")) {
if(!furi_string_cmp(args, "0")) {
furi_hal_power_disable_otg();
} else if(!string_cmp(args, "1")) {
} else if(!furi_string_cmp(args, "1")) {
furi_hal_power_enable_otg();
} else {
cli_print_usage("power_otg", "<1|0>", string_get_cstr(args));
cli_print_usage("power_otg", "<1|0>", furi_string_get_cstr(args));
}
}
void power_cli_3v3(Cli* cli, string_t args) {
void power_cli_3v3(Cli* cli, FuriString* args) {
UNUSED(cli);
if(!string_cmp(args, "0")) {
if(!furi_string_cmp(args, "0")) {
furi_hal_power_disable_external_3_3v();
} else if(!string_cmp(args, "1")) {
} else if(!furi_string_cmp(args, "1")) {
furi_hal_power_enable_external_3_3v();
} else {
cli_print_usage("power_ext", "<1|0>", string_get_cstr(args));
cli_print_usage("power_ext", "<1|0>", furi_string_get_cstr(args));
}
}
@@ -82,10 +82,10 @@ static void power_cli_command_print_usage() {
}
}
void power_cli(Cli* cli, string_t args, void* context) {
void power_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
string_t cmd;
string_init(cmd);
FuriString* cmd;
cmd = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
@@ -93,38 +93,38 @@ void power_cli(Cli* cli, string_t args, void* context) {
break;
}
if(string_cmp_str(cmd, "off") == 0) {
if(furi_string_cmp_str(cmd, "off") == 0) {
power_cli_off(cli, args);
break;
}
if(string_cmp_str(cmd, "reboot") == 0) {
if(furi_string_cmp_str(cmd, "reboot") == 0) {
power_cli_reboot(cli, args);
break;
}
if(string_cmp_str(cmd, "reboot2dfu") == 0) {
if(furi_string_cmp_str(cmd, "reboot2dfu") == 0) {
power_cli_reboot2dfu(cli, args);
break;
}
if(string_cmp_str(cmd, "info") == 0) {
if(furi_string_cmp_str(cmd, "info") == 0) {
power_cli_info(cli, args);
break;
}
if(string_cmp_str(cmd, "debug") == 0) {
if(furi_string_cmp_str(cmd, "debug") == 0) {
power_cli_debug(cli, args);
break;
}
if(string_cmp_str(cmd, "5v") == 0) {
if(furi_string_cmp_str(cmd, "5v") == 0) {
power_cli_5v(cli, args);
break;
}
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
if(string_cmp_str(cmd, "3v3") == 0) {
if(furi_string_cmp_str(cmd, "3v3") == 0) {
power_cli_3v3(cli, args);
break;
}
@@ -133,7 +133,7 @@ void power_cli(Cli* cli, string_t args, void* context) {
power_cli_command_print_usage();
} while(false);
string_clear(cmd);
furi_string_free(cmd);
}
void power_on_system_start() {
-1
View File
@@ -14,7 +14,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stream_buffer.h>
#include <m-string.h>
#include <m-dict.h>
#define TAG "RpcSrv"
+1 -1
View File
@@ -37,7 +37,7 @@ static void rpc_cli_session_terminated_callback(void* context) {
furi_semaphore_release(cli_rpc->terminate_semaphore);
}
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context) {
UNUSED(args);
furi_assert(cli);
furi_assert(context);
+73 -74
View File
@@ -1,15 +1,14 @@
#include "rpc_i.h"
#include <m-string.h>
static size_t rpc_debug_print_file_msg(
string_t str,
FuriString* str,
const char* prefix,
const PB_Storage_File* msg_file,
size_t msg_files_size) {
size_t cnt = 0;
for(size_t i = 0; i < msg_files_size; ++i, ++msg_file) {
string_cat_printf(
furi_string_cat_printf(
str,
"%s[%c] size: %5ld",
prefix,
@@ -17,11 +16,11 @@ static size_t rpc_debug_print_file_msg(
msg_file->size);
if(msg_file->name) {
string_cat_printf(str, " \'%s\'", msg_file->name);
furi_string_cat_printf(str, " \'%s\'", msg_file->name);
}
if(msg_file->data && msg_file->data->size) {
string_cat_printf(
furi_string_cat_printf(
str,
" (%d):\'%.*s%s\'",
msg_file->data->size,
@@ -30,42 +29,42 @@ static size_t rpc_debug_print_file_msg(
msg_file->data->size > 30 ? "..." : "");
}
string_cat_printf(str, "\r\n");
furi_string_cat_printf(str, "\r\n");
}
return cnt;
}
void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size) {
string_t str;
string_init(str);
string_reserve(str, 100 + size * 5);
FuriString* str;
str = furi_string_alloc();
furi_string_reserve(str, 100 + size * 5);
string_cat_printf(str, "\r\n%s DEC(%d): {", prefix, size);
furi_string_cat_printf(str, "\r\n%s DEC(%d): {", prefix, size);
for(size_t i = 0; i < size; ++i) {
string_cat_printf(str, "%d, ", buffer[i]);
furi_string_cat_printf(str, "%d, ", buffer[i]);
}
string_cat_printf(str, "}\r\n");
furi_string_cat_printf(str, "}\r\n");
printf("%s", string_get_cstr(str));
string_reset(str);
string_reserve(str, 100 + size * 3);
printf("%s", furi_string_get_cstr(str));
furi_string_reset(str);
furi_string_reserve(str, 100 + size * 3);
string_cat_printf(str, "%s HEX(%d): {", prefix, size);
furi_string_cat_printf(str, "%s HEX(%d): {", prefix, size);
for(size_t i = 0; i < size; ++i) {
string_cat_printf(str, "%02X", buffer[i]);
furi_string_cat_printf(str, "%02X", buffer[i]);
}
string_cat_printf(str, "}\r\n\r\n");
furi_string_cat_printf(str, "}\r\n\r\n");
printf("%s", string_get_cstr(str));
string_clear(str);
printf("%s", furi_string_get_cstr(str));
furi_string_free(str);
}
void rpc_debug_print_message(const PB_Main* message) {
string_t str;
string_init(str);
FuriString* str;
str = furi_string_alloc();
string_cat_printf(
furi_string_cat_printf(
str,
"PB_Main: {\r\n\tresult: %d cmd_id: %ld (%s)\r\n",
message->command_status,
@@ -74,106 +73,106 @@ void rpc_debug_print_message(const PB_Main* message) {
switch(message->which_content) {
default:
/* not implemented yet */
string_cat_printf(str, "\tNOT_IMPLEMENTED (%d) {\r\n", message->which_content);
furi_string_cat_printf(str, "\tNOT_IMPLEMENTED (%d) {\r\n", message->which_content);
break;
case PB_Main_stop_session_tag:
string_cat_printf(str, "\tstop_session {\r\n");
furi_string_cat_printf(str, "\tstop_session {\r\n");
break;
case PB_Main_app_start_request_tag: {
string_cat_printf(str, "\tapp_start {\r\n");
furi_string_cat_printf(str, "\tapp_start {\r\n");
const char* name = message->content.app_start_request.name;
const char* args = message->content.app_start_request.args;
if(name) {
string_cat_printf(str, "\t\tname: %s\r\n", name);
furi_string_cat_printf(str, "\t\tname: %s\r\n", name);
}
if(args) {
string_cat_printf(str, "\t\targs: %s\r\n", args);
furi_string_cat_printf(str, "\t\targs: %s\r\n", args);
}
break;
}
case PB_Main_app_lock_status_request_tag: {
string_cat_printf(str, "\tapp_lock_status_request {\r\n");
furi_string_cat_printf(str, "\tapp_lock_status_request {\r\n");
break;
}
case PB_Main_app_lock_status_response_tag: {
string_cat_printf(str, "\tapp_lock_status_response {\r\n");
furi_string_cat_printf(str, "\tapp_lock_status_response {\r\n");
bool lock_status = message->content.app_lock_status_response.locked;
string_cat_printf(str, "\t\tlocked: %s\r\n", lock_status ? "true" : "false");
furi_string_cat_printf(str, "\t\tlocked: %s\r\n", lock_status ? "true" : "false");
break;
}
case PB_Main_storage_md5sum_request_tag: {
string_cat_printf(str, "\tmd5sum_request {\r\n");
furi_string_cat_printf(str, "\tmd5sum_request {\r\n");
const char* path = message->content.storage_md5sum_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_storage_md5sum_response_tag: {
string_cat_printf(str, "\tmd5sum_response {\r\n");
furi_string_cat_printf(str, "\tmd5sum_response {\r\n");
const char* path = message->content.storage_md5sum_response.md5sum;
if(path) {
string_cat_printf(str, "\t\tmd5sum: %s\r\n", path);
furi_string_cat_printf(str, "\t\tmd5sum: %s\r\n", path);
}
break;
}
case PB_Main_system_ping_request_tag:
string_cat_printf(str, "\tping_request {\r\n");
furi_string_cat_printf(str, "\tping_request {\r\n");
break;
case PB_Main_system_ping_response_tag:
string_cat_printf(str, "\tping_response {\r\n");
furi_string_cat_printf(str, "\tping_response {\r\n");
break;
case PB_Main_system_device_info_request_tag:
string_cat_printf(str, "\tdevice_info_request {\r\n");
furi_string_cat_printf(str, "\tdevice_info_request {\r\n");
break;
case PB_Main_system_device_info_response_tag:
string_cat_printf(str, "\tdevice_info_response {\r\n");
string_cat_printf(
furi_string_cat_printf(str, "\tdevice_info_response {\r\n");
furi_string_cat_printf(
str,
"\t\t%s: %s\r\n",
message->content.system_device_info_response.key,
message->content.system_device_info_response.value);
break;
case PB_Main_storage_mkdir_request_tag:
string_cat_printf(str, "\tmkdir {\r\n");
furi_string_cat_printf(str, "\tmkdir {\r\n");
break;
case PB_Main_storage_delete_request_tag: {
string_cat_printf(str, "\tdelete {\r\n");
furi_string_cat_printf(str, "\tdelete {\r\n");
const char* path = message->content.storage_delete_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_empty_tag:
string_cat_printf(str, "\tempty {\r\n");
furi_string_cat_printf(str, "\tempty {\r\n");
break;
case PB_Main_storage_info_request_tag: {
string_cat_printf(str, "\tinfo_request {\r\n");
furi_string_cat_printf(str, "\tinfo_request {\r\n");
const char* path = message->content.storage_info_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_storage_info_response_tag: {
string_cat_printf(str, "\tinfo_response {\r\n");
string_cat_printf(
furi_string_cat_printf(str, "\tinfo_response {\r\n");
furi_string_cat_printf(
str, "\t\ttotal_space: %lu\r\n", message->content.storage_info_response.total_space);
string_cat_printf(
furi_string_cat_printf(
str, "\t\tfree_space: %lu\r\n", message->content.storage_info_response.free_space);
break;
}
case PB_Main_storage_stat_request_tag: {
string_cat_printf(str, "\tstat_request {\r\n");
furi_string_cat_printf(str, "\tstat_request {\r\n");
const char* path = message->content.storage_stat_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_storage_stat_response_tag: {
string_cat_printf(str, "\tstat_response {\r\n");
furi_string_cat_printf(str, "\tstat_response {\r\n");
if(message->content.storage_stat_response.has_file) {
const PB_Storage_File* msg_file = &message->content.storage_stat_response.file;
rpc_debug_print_file_msg(str, "\t\t\t", msg_file, 1);
@@ -181,26 +180,26 @@ void rpc_debug_print_message(const PB_Main* message) {
break;
}
case PB_Main_storage_list_request_tag: {
string_cat_printf(str, "\tlist_request {\r\n");
furi_string_cat_printf(str, "\tlist_request {\r\n");
const char* path = message->content.storage_list_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_storage_read_request_tag: {
string_cat_printf(str, "\tread_request {\r\n");
furi_string_cat_printf(str, "\tread_request {\r\n");
const char* path = message->content.storage_read_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
break;
}
case PB_Main_storage_write_request_tag: {
string_cat_printf(str, "\twrite_request {\r\n");
furi_string_cat_printf(str, "\twrite_request {\r\n");
const char* path = message->content.storage_write_request.path;
if(path) {
string_cat_printf(str, "\t\tpath: %s\r\n", path);
furi_string_cat_printf(str, "\t\tpath: %s\r\n", path);
}
if(message->content.storage_write_request.has_file) {
const PB_Storage_File* msg_file = &message->content.storage_write_request.file;
@@ -209,7 +208,7 @@ void rpc_debug_print_message(const PB_Main* message) {
break;
}
case PB_Main_storage_read_response_tag:
string_cat_printf(str, "\tread_response {\r\n");
furi_string_cat_printf(str, "\tread_response {\r\n");
if(message->content.storage_read_response.has_file) {
const PB_Storage_File* msg_file = &message->content.storage_read_response.file;
rpc_debug_print_file_msg(str, "\t\t\t", msg_file, 1);
@@ -218,43 +217,43 @@ void rpc_debug_print_message(const PB_Main* message) {
case PB_Main_storage_list_response_tag: {
const PB_Storage_File* msg_file = message->content.storage_list_response.file;
size_t msg_file_count = message->content.storage_list_response.file_count;
string_cat_printf(str, "\tlist_response {\r\n");
furi_string_cat_printf(str, "\tlist_response {\r\n");
rpc_debug_print_file_msg(str, "\t\t", msg_file, msg_file_count);
break;
}
case PB_Main_storage_rename_request_tag: {
string_cat_printf(str, "\trename_request {\r\n");
string_cat_printf(
furi_string_cat_printf(str, "\trename_request {\r\n");
furi_string_cat_printf(
str, "\t\told_path: %s\r\n", message->content.storage_rename_request.old_path);
string_cat_printf(
furi_string_cat_printf(
str, "\t\tnew_path: %s\r\n", message->content.storage_rename_request.new_path);
break;
}
case PB_Main_gui_start_screen_stream_request_tag:
string_cat_printf(str, "\tstart_screen_stream {\r\n");
furi_string_cat_printf(str, "\tstart_screen_stream {\r\n");
break;
case PB_Main_gui_stop_screen_stream_request_tag:
string_cat_printf(str, "\tstop_screen_stream {\r\n");
furi_string_cat_printf(str, "\tstop_screen_stream {\r\n");
break;
case PB_Main_gui_screen_frame_tag:
string_cat_printf(str, "\tscreen_frame {\r\n");
furi_string_cat_printf(str, "\tscreen_frame {\r\n");
break;
case PB_Main_gui_send_input_event_request_tag:
string_cat_printf(str, "\tsend_input_event {\r\n");
string_cat_printf(
furi_string_cat_printf(str, "\tsend_input_event {\r\n");
furi_string_cat_printf(
str, "\t\tkey: %d\r\n", message->content.gui_send_input_event_request.key);
string_cat_printf(
furi_string_cat_printf(
str, "\t\type: %d\r\n", message->content.gui_send_input_event_request.type);
break;
case PB_Main_gui_start_virtual_display_request_tag:
string_cat_printf(str, "\tstart_virtual_display {\r\n");
furi_string_cat_printf(str, "\tstart_virtual_display {\r\n");
break;
case PB_Main_gui_stop_virtual_display_request_tag:
string_cat_printf(str, "\tstop_virtual_display {\r\n");
furi_string_cat_printf(str, "\tstop_virtual_display {\r\n");
break;
}
string_cat_printf(str, "\t}\r\n}\r\n");
printf("%s", string_get_cstr(str));
furi_string_cat_printf(str, "\t}\r\n}\r\n");
printf("%s", furi_string_get_cstr(str));
string_clear(str);
furi_string_free(str);
}
+1 -1
View File
@@ -38,6 +38,6 @@ void rpc_system_gpio_free(void* ctx);
void rpc_debug_print_message(const PB_Main* message);
void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size);
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context);
void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context);
PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error);
+2 -3
View File
@@ -1,6 +1,5 @@
#pragma once
#include <stdint.h>
#include <m-string.h>
#include "filesystem_api_defines.h"
#include "storage_sd_api.h"
@@ -292,7 +291,7 @@ FS_Error storage_sd_status(Storage* api);
/******************* Internal LFS Functions *******************/
typedef void (*Storage_name_converter)(string_t);
typedef void (*Storage_name_converter)(FuriString*);
/** Backs up internal storage to a tar archive
* @param api pointer to the api
@@ -350,7 +349,7 @@ void storage_get_next_filename(
const char* dirname,
const char* filename,
const char* fileextension,
string_t nextfilename,
FuriString* nextfilename,
uint8_t max_len);
#ifdef __cplusplus
+79 -76
View File
@@ -38,11 +38,11 @@ static void storage_cli_print_error(FS_Error error) {
printf("Storage error: %s\r\n", storage_error_get_desc(error));
}
static void storage_cli_info(Cli* cli, string_t path) {
static void storage_cli_info(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
if(string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
uint64_t total_space;
uint64_t free_space;
FS_Error error =
@@ -57,7 +57,7 @@ static void storage_cli_info(Cli* cli, string_t path) {
(uint32_t)(total_space / 1024),
(uint32_t)(free_space / 1024));
}
} else if(string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
SDInfo sd_info;
FS_Error error = storage_sd_info(api, &sd_info);
@@ -78,10 +78,10 @@ static void storage_cli_info(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
};
static void storage_cli_format(Cli* cli, string_t path) {
if(string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
static void storage_cli_format(Cli* cli, FuriString* path) {
if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
storage_cli_print_error(FSE_NOT_IMPLEMENTED);
} else if(string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
printf("Formatting SD card, All data will be lost! Are you sure (y/n)?\r\n");
char answer = cli_getc(cli);
if(answer == 'y' || answer == 'Y') {
@@ -104,9 +104,9 @@ static void storage_cli_format(Cli* cli, string_t path) {
}
};
static void storage_cli_list(Cli* cli, string_t path) {
static void storage_cli_list(Cli* cli, FuriString* path) {
UNUSED(cli);
if(string_cmp_str(path, "/") == 0) {
if(furi_string_cmp_str(path, "/") == 0) {
printf("\t[D] int\r\n");
printf("\t[D] ext\r\n");
printf("\t[D] any\r\n");
@@ -114,7 +114,7 @@ static void storage_cli_list(Cli* cli, string_t path) {
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
if(storage_dir_open(file, string_get_cstr(path))) {
if(storage_dir_open(file, furi_string_get_cstr(path))) {
FileInfo fileinfo;
char name[MAX_NAME_LENGTH];
bool read_done = false;
@@ -141,28 +141,31 @@ static void storage_cli_list(Cli* cli, string_t path) {
}
}
static void storage_cli_tree(Cli* cli, string_t path) {
if(string_cmp_str(path, "/") == 0) {
string_set(path, STORAGE_INT_PATH_PREFIX);
static void storage_cli_tree(Cli* cli, FuriString* path) {
if(furi_string_cmp_str(path, "/") == 0) {
furi_string_set(path, STORAGE_INT_PATH_PREFIX);
storage_cli_tree(cli, path);
string_set(path, STORAGE_EXT_PATH_PREFIX);
furi_string_set(path, STORAGE_EXT_PATH_PREFIX);
storage_cli_tree(cli, path);
} else {
Storage* api = furi_record_open(RECORD_STORAGE);
DirWalk* dir_walk = dir_walk_alloc(api);
string_t name;
string_init(name);
FuriString* name;
name = furi_string_alloc();
if(dir_walk_open(dir_walk, string_get_cstr(path))) {
if(dir_walk_open(dir_walk, furi_string_get_cstr(path))) {
FileInfo fileinfo;
bool read_done = false;
while(dir_walk_read(dir_walk, name, &fileinfo) == DirWalkOK) {
read_done = true;
if(fileinfo.flags & FSF_DIRECTORY) {
printf("\t[D] %s\r\n", string_get_cstr(name));
printf("\t[D] %s\r\n", furi_string_get_cstr(name));
} else {
printf("\t[F] %s %lub\r\n", string_get_cstr(name), (uint32_t)(fileinfo.size));
printf(
"\t[F] %s %lub\r\n",
furi_string_get_cstr(name),
(uint32_t)(fileinfo.size));
}
}
@@ -173,18 +176,18 @@ static void storage_cli_tree(Cli* cli, string_t path) {
storage_cli_print_error(dir_walk_get_error(dir_walk));
}
string_clear(name);
furi_string_free(name);
dir_walk_free(dir_walk);
furi_record_close(RECORD_STORAGE);
}
}
static void storage_cli_read(Cli* cli, string_t path) {
static void storage_cli_read(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
const uint16_t buffer_size = 128;
uint16_t read_size = 0;
uint8_t* data = malloc(buffer_size);
@@ -210,14 +213,14 @@ static void storage_cli_read(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_write(Cli* cli, string_t path) {
static void storage_cli_write(Cli* cli, FuriString* path) {
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
const uint16_t buffer_size = 512;
uint8_t* buffer = malloc(buffer_size);
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
printf("Just write your text data. New line by Ctrl+Enter, exit by Ctrl+C.\r\n");
uint32_t read_index = 0;
@@ -264,16 +267,16 @@ static void storage_cli_write(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args) {
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
uint32_t buffer_size;
int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size);
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
if(parsed_count == EOF || parsed_count != 1) {
storage_cli_print_usage();
} else if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
} else if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
uint64_t file_size = storage_file_size(file);
printf("Size: %lu\r\n", (uint32_t)file_size);
@@ -304,17 +307,17 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args) {
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
uint32_t buffer_size;
int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size);
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
if(parsed_count == EOF || parsed_count != 1) {
storage_cli_print_usage();
} else {
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
printf("Ready\r\n");
if(buffer_size) {
@@ -342,20 +345,20 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_stat(Cli* cli, string_t path) {
static void storage_cli_stat(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
if(string_cmp_str(path, "/") == 0) {
if(furi_string_cmp_str(path, "/") == 0) {
printf("Storage\r\n");
} else if(
string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0 ||
string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0 ||
string_cmp_str(path, STORAGE_ANY_PATH_PREFIX) == 0) {
furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0 ||
furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0 ||
furi_string_cmp_str(path, STORAGE_ANY_PATH_PREFIX) == 0) {
uint64_t total_space;
uint64_t free_space;
FS_Error error =
storage_common_fs_info(api, string_get_cstr(path), &total_space, &free_space);
storage_common_fs_info(api, furi_string_get_cstr(path), &total_space, &free_space);
if(error != FSE_OK) {
storage_cli_print_error(error);
@@ -367,7 +370,7 @@ static void storage_cli_stat(Cli* cli, string_t path) {
}
} else {
FileInfo fileinfo;
FS_Error error = storage_common_stat(api, string_get_cstr(path), &fileinfo);
FS_Error error = storage_common_stat(api, furi_string_get_cstr(path), &fileinfo);
if(error == FSE_OK) {
if(fileinfo.flags & FSF_DIRECTORY) {
@@ -383,31 +386,31 @@ static void storage_cli_stat(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_copy(Cli* cli, string_t old_path, string_t args) {
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
string_t new_path;
string_init(new_path);
FuriString* new_path;
new_path = furi_string_alloc();
if(!args_read_probably_quoted_string_and_trim(args, new_path)) {
storage_cli_print_usage();
} else {
FS_Error error =
storage_common_copy(api, string_get_cstr(old_path), string_get_cstr(new_path));
FS_Error error = storage_common_copy(
api, furi_string_get_cstr(old_path), furi_string_get_cstr(new_path));
if(error != FSE_OK) {
storage_cli_print_error(error);
}
}
string_clear(new_path);
furi_string_free(new_path);
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_remove(Cli* cli, string_t path) {
static void storage_cli_remove(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
FS_Error error = storage_common_remove(api, string_get_cstr(path));
FS_Error error = storage_common_remove(api, furi_string_get_cstr(path));
if(error != FSE_OK) {
storage_cli_print_error(error);
@@ -416,31 +419,31 @@ static void storage_cli_remove(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_rename(Cli* cli, string_t old_path, string_t args) {
static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
string_t new_path;
string_init(new_path);
FuriString* new_path;
new_path = furi_string_alloc();
if(!args_read_probably_quoted_string_and_trim(args, new_path)) {
storage_cli_print_usage();
} else {
FS_Error error =
storage_common_rename(api, string_get_cstr(old_path), string_get_cstr(new_path));
FS_Error error = storage_common_rename(
api, furi_string_get_cstr(old_path), furi_string_get_cstr(new_path));
if(error != FSE_OK) {
storage_cli_print_error(error);
}
}
string_clear(new_path);
furi_string_free(new_path);
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_mkdir(Cli* cli, string_t path) {
static void storage_cli_mkdir(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
FS_Error error = storage_common_mkdir(api, string_get_cstr(path));
FS_Error error = storage_common_mkdir(api, furi_string_get_cstr(path));
if(error != FSE_OK) {
storage_cli_print_error(error);
@@ -449,12 +452,12 @@ static void storage_cli_mkdir(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
static void storage_cli_md5(Cli* cli, string_t path) {
static void storage_cli_md5(Cli* cli, FuriString* path) {
UNUSED(cli);
Storage* api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(api);
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
const uint16_t buffer_size = 512;
const uint8_t hash_size = 16;
uint8_t* data = malloc(buffer_size);
@@ -487,12 +490,12 @@ static void storage_cli_md5(Cli* cli, string_t path) {
furi_record_close(RECORD_STORAGE);
}
void storage_cli(Cli* cli, string_t args, void* context) {
void storage_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
string_t cmd;
string_t path;
string_init(cmd);
string_init(path);
FuriString* cmd;
FuriString* path;
cmd = furi_string_alloc();
path = furi_string_alloc();
do {
if(!args_read_string_and_trim(args, cmd)) {
@@ -505,72 +508,72 @@ void storage_cli(Cli* cli, string_t args, void* context) {
break;
}
if(string_cmp_str(cmd, "info") == 0) {
if(furi_string_cmp_str(cmd, "info") == 0) {
storage_cli_info(cli, path);
break;
}
if(string_cmp_str(cmd, "format") == 0) {
if(furi_string_cmp_str(cmd, "format") == 0) {
storage_cli_format(cli, path);
break;
}
if(string_cmp_str(cmd, "list") == 0) {
if(furi_string_cmp_str(cmd, "list") == 0) {
storage_cli_list(cli, path);
break;
}
if(string_cmp_str(cmd, "tree") == 0) {
if(furi_string_cmp_str(cmd, "tree") == 0) {
storage_cli_tree(cli, path);
break;
}
if(string_cmp_str(cmd, "read") == 0) {
if(furi_string_cmp_str(cmd, "read") == 0) {
storage_cli_read(cli, path);
break;
}
if(string_cmp_str(cmd, "read_chunks") == 0) {
if(furi_string_cmp_str(cmd, "read_chunks") == 0) {
storage_cli_read_chunks(cli, path, args);
break;
}
if(string_cmp_str(cmd, "write") == 0) {
if(furi_string_cmp_str(cmd, "write") == 0) {
storage_cli_write(cli, path);
break;
}
if(string_cmp_str(cmd, "write_chunk") == 0) {
if(furi_string_cmp_str(cmd, "write_chunk") == 0) {
storage_cli_write_chunk(cli, path, args);
break;
}
if(string_cmp_str(cmd, "copy") == 0) {
if(furi_string_cmp_str(cmd, "copy") == 0) {
storage_cli_copy(cli, path, args);
break;
}
if(string_cmp_str(cmd, "remove") == 0) {
if(furi_string_cmp_str(cmd, "remove") == 0) {
storage_cli_remove(cli, path);
break;
}
if(string_cmp_str(cmd, "rename") == 0) {
if(furi_string_cmp_str(cmd, "rename") == 0) {
storage_cli_rename(cli, path, args);
break;
}
if(string_cmp_str(cmd, "mkdir") == 0) {
if(furi_string_cmp_str(cmd, "mkdir") == 0) {
storage_cli_mkdir(cli, path);
break;
}
if(string_cmp_str(cmd, "md5") == 0) {
if(furi_string_cmp_str(cmd, "md5") == 0) {
storage_cli_md5(cli, path);
break;
}
if(string_cmp_str(cmd, "stat") == 0) {
if(furi_string_cmp_str(cmd, "stat") == 0) {
storage_cli_stat(cli, path);
break;
}
@@ -578,11 +581,11 @@ void storage_cli(Cli* cli, string_t args, void* context) {
storage_cli_print_usage();
} while(false);
string_clear(path);
string_clear(cmd);
furi_string_free(path);
furi_string_free(cmd);
}
static void storage_cli_factory_reset(Cli* cli, string_t args, void* context) {
static void storage_cli_factory_reset(Cli* cli, FuriString* args, void* context) {
UNUSED(args);
UNUSED(context);
printf("All data will be lost! Are you sure (y/n)?\r\n");
@@ -1,6 +1,5 @@
#include <core/log.h>
#include <core/record.h>
#include <m-string.h>
#include "storage.h"
#include "storage_i.h"
#include "storage_message.h"
@@ -374,13 +373,13 @@ static FS_Error
storage_copy_recursive(Storage* storage, const char* old_path, const char* new_path) {
FS_Error error = storage_common_mkdir(storage, new_path);
DirWalk* dir_walk = dir_walk_alloc(storage);
string_t path;
string_t tmp_new_path;
string_t tmp_old_path;
FuriString* path;
FuriString* tmp_new_path;
FuriString* tmp_old_path;
FileInfo fileinfo;
string_init(path);
string_init(tmp_new_path);
string_init(tmp_old_path);
path = furi_string_alloc();
tmp_new_path = furi_string_alloc();
tmp_old_path = furi_string_alloc();
do {
if(error != FSE_OK) break;
@@ -399,15 +398,17 @@ static FS_Error
} else if(res == DirWalkLast) {
break;
} else {
string_set(tmp_old_path, path);
string_right(path, strlen(old_path));
string_printf(tmp_new_path, "%s%s", new_path, string_get_cstr(path));
furi_string_set(tmp_old_path, path);
furi_string_right(path, strlen(old_path));
furi_string_printf(tmp_new_path, "%s%s", new_path, furi_string_get_cstr(path));
if(fileinfo.flags & FSF_DIRECTORY) {
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
error = storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
} else {
error = storage_common_copy(
storage, string_get_cstr(tmp_old_path), string_get_cstr(tmp_new_path));
storage,
furi_string_get_cstr(tmp_old_path),
furi_string_get_cstr(tmp_new_path));
}
if(error != FSE_OK) break;
@@ -416,9 +417,9 @@ static FS_Error
} while(false);
string_clear(tmp_new_path);
string_clear(tmp_old_path);
string_clear(path);
furi_string_free(tmp_new_path);
furi_string_free(tmp_old_path);
furi_string_free(path);
dir_walk_free(dir_walk);
return error;
}
@@ -459,11 +460,11 @@ static FS_Error
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
FS_Error error = storage_common_mkdir(storage, new_path);
DirWalk* dir_walk = dir_walk_alloc(storage);
string_t path, file_basename, tmp_new_path;
FuriString *path, *file_basename, *tmp_new_path;
FileInfo fileinfo;
string_init(path);
string_init(file_basename);
string_init(tmp_new_path);
path = furi_string_alloc();
file_basename = furi_string_alloc();
tmp_new_path = furi_string_alloc();
do {
if((error != FSE_OK) && (error != FSE_EXIST)) break;
@@ -483,14 +484,15 @@ static FS_Error
} else if(res == DirWalkLast) {
break;
} else {
path_extract_basename(string_get_cstr(path), file_basename);
path_concat(new_path, string_get_cstr(file_basename), tmp_new_path);
path_extract_basename(furi_string_get_cstr(path), file_basename);
path_concat(new_path, furi_string_get_cstr(file_basename), tmp_new_path);
if(fileinfo.flags & FSF_DIRECTORY) {
if(storage_common_stat(storage, string_get_cstr(tmp_new_path), &fileinfo) ==
FSE_OK) {
if(storage_common_stat(
storage, furi_string_get_cstr(tmp_new_path), &fileinfo) == FSE_OK) {
if(fileinfo.flags & FSF_DIRECTORY) {
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
error =
storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
if(error != FSE_OK) {
break;
}
@@ -498,7 +500,7 @@ static FS_Error
}
}
error = storage_common_merge(
storage, string_get_cstr(path), string_get_cstr(tmp_new_path));
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path));
if(error != FSE_OK) {
break;
@@ -508,9 +510,9 @@ static FS_Error
} while(false);
string_clear(tmp_new_path);
string_clear(file_basename);
string_clear(path);
furi_string_free(tmp_new_path);
furi_string_free(file_basename);
furi_string_free(path);
dir_walk_free(dir_walk);
return error;
}
@@ -518,8 +520,8 @@ static FS_Error
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
FS_Error error;
const char* new_path_tmp;
string_t new_path_next;
string_init(new_path_next);
FuriString* new_path_next;
new_path_next = furi_string_alloc();
FileInfo fileinfo;
error = storage_common_stat(storage, old_path, &fileinfo);
@@ -530,13 +532,13 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
} else {
error = storage_common_stat(storage, new_path, &fileinfo);
if(error == FSE_OK) {
string_set_str(new_path_next, new_path);
string_t dir_path;
string_t filename;
furi_string_set(new_path_next, new_path);
FuriString* dir_path;
FuriString* filename;
char extension[MAX_EXT_LEN];
string_init(dir_path);
string_init(filename);
dir_path = furi_string_alloc();
filename = furi_string_alloc();
path_extract_filename(new_path_next, filename, true);
path_extract_dirname(new_path, dir_path);
@@ -544,17 +546,18 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
storage_get_next_filename(
storage,
string_get_cstr(dir_path),
string_get_cstr(filename),
furi_string_get_cstr(dir_path),
furi_string_get_cstr(filename),
extension,
new_path_next,
255);
string_cat_printf(dir_path, "/%s%s", string_get_cstr(new_path_next), extension);
string_set(new_path_next, dir_path);
furi_string_cat_printf(
dir_path, "/%s%s", furi_string_get_cstr(new_path_next), extension);
furi_string_set(new_path_next, dir_path);
string_clear(dir_path);
string_clear(filename);
new_path_tmp = string_get_cstr(new_path_next);
furi_string_free(dir_path);
furi_string_free(filename);
new_path_tmp = furi_string_get_cstr(new_path_next);
} else {
new_path_tmp = new_path;
}
@@ -577,7 +580,7 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
}
}
string_clear(new_path_next);
furi_string_free(new_path_next);
return error;
}
@@ -707,8 +710,8 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
furi_assert(path);
FileInfo fileinfo;
bool result = false;
string_t fullname;
string_t cur_dir;
FuriString* fullname;
FuriString* cur_dir;
if(storage_simply_remove(storage, path)) {
return true;
@@ -716,26 +719,26 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
char* name = malloc(MAX_NAME_LENGTH + 1);
File* dir = storage_file_alloc(storage);
string_init_set_str(cur_dir, path);
cur_dir = furi_string_alloc_set(path);
bool go_deeper = false;
while(1) {
if(!storage_dir_open(dir, string_get_cstr(cur_dir))) {
if(!storage_dir_open(dir, furi_string_get_cstr(cur_dir))) {
storage_dir_close(dir);
break;
}
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
if(fileinfo.flags & FSF_DIRECTORY) {
string_cat_printf(cur_dir, "/%s", name);
furi_string_cat_printf(cur_dir, "/%s", name);
go_deeper = true;
break;
}
string_init_printf(fullname, "%s/%s", string_get_cstr(cur_dir), name);
FS_Error error = storage_common_remove(storage, string_get_cstr(fullname));
fullname = furi_string_alloc_printf("%s/%s", furi_string_get_cstr(cur_dir), name);
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(fullname));
furi_check(error == FSE_OK);
string_clear(fullname);
furi_string_free(fullname);
}
storage_dir_close(dir);
@@ -744,13 +747,13 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
continue;
}
FS_Error error = storage_common_remove(storage, string_get_cstr(cur_dir));
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(cur_dir));
furi_check(error == FSE_OK);
if(string_cmp(cur_dir, path)) {
size_t last_char = string_search_rchar(cur_dir, '/');
furi_assert(last_char != STRING_FAILURE);
string_left(cur_dir, last_char);
if(furi_string_cmp(cur_dir, path)) {
size_t last_char = furi_string_search_rchar(cur_dir, '/');
furi_assert(last_char != FURI_STRING_FAILURE);
furi_string_left(cur_dir, last_char);
} else {
result = true;
break;
@@ -758,7 +761,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
}
storage_file_free(dir);
string_clear(cur_dir);
furi_string_free(cur_dir);
free(name);
return result;
}
@@ -780,22 +783,22 @@ void storage_get_next_filename(
const char* dirname,
const char* filename,
const char* fileextension,
string_t nextfilename,
FuriString* nextfilename,
uint8_t max_len) {
string_t temp_str;
FuriString* temp_str;
uint16_t num = 0;
string_init_printf(temp_str, "%s/%s%s", dirname, filename, fileextension);
temp_str = furi_string_alloc_printf("%s/%s%s", dirname, filename, fileextension);
while(storage_common_stat(storage, string_get_cstr(temp_str), NULL) == FSE_OK) {
while(storage_common_stat(storage, furi_string_get_cstr(temp_str), NULL) == FSE_OK) {
num++;
string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
furi_string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
}
if(num && (max_len > strlen(filename))) {
string_printf(nextfilename, "%s%d", filename, num);
furi_string_printf(nextfilename, "%s%d", filename, num);
} else {
string_printf(nextfilename, "%s", filename);
furi_string_printf(nextfilename, "%s", filename);
}
string_clear(temp_str);
furi_string_free(temp_str);
}
+12 -8
View File
@@ -7,25 +7,25 @@ void storage_file_init(StorageFile* obj) {
obj->file = NULL;
obj->type = ST_ERROR;
obj->file_data = NULL;
string_init(obj->path);
obj->path = furi_string_alloc();
}
void storage_file_init_set(StorageFile* obj, const StorageFile* src) {
obj->file = src->file;
obj->type = src->type;
obj->file_data = src->file_data;
string_init_set(obj->path, src->path);
obj->path = furi_string_alloc_set(src->path);
}
void storage_file_set(StorageFile* obj, const StorageFile* src) {
obj->file = src->file;
obj->type = src->type;
obj->file_data = src->file_data;
string_set(obj->path, src->path);
furi_string_set(obj->path, src->path);
}
void storage_file_clear(StorageFile* obj) {
string_clear(obj->path);
furi_string_free(obj->path);
}
/****************** storage data ******************/
@@ -101,7 +101,7 @@ bool storage_has_file(const File* file, StorageData* storage_data) {
return result;
}
bool storage_path_already_open(string_t path, StorageFileList_t array) {
bool storage_path_already_open(FuriString* path, StorageFileList_t array) {
bool open = false;
StorageFileList_it_t it;
@@ -109,7 +109,7 @@ bool storage_path_already_open(string_t path, StorageFileList_t array) {
for(StorageFileList_it(it, array); !StorageFileList_end_p(it); StorageFileList_next(it)) {
const StorageFile* storage_file = StorageFileList_cref(it);
if(string_cmp(storage_file->path, path) == 0) {
if(furi_string_cmp(storage_file->path, path) == 0) {
open = true;
break;
}
@@ -158,14 +158,18 @@ void* storage_get_storage_file_data(const File* file, StorageData* storage) {
return founded_file->file_data;
}
void storage_push_storage_file(File* file, string_t path, StorageType type, StorageData* storage) {
void storage_push_storage_file(
File* file,
FuriString* path,
StorageType type,
StorageData* storage) {
StorageFile* storage_file = StorageFileList_push_new(storage->files);
furi_check(storage_file != NULL);
file->file_id = (uint32_t)storage_file;
storage_file->file = file;
storage_file->type = type;
string_set(storage_file->path, path);
furi_string_set(storage_file->path, path);
}
bool storage_pop_storage_file(File* file, StorageData* storage) {
+7 -4
View File
@@ -2,7 +2,6 @@
#include <furi.h>
#include "filesystem_api_internal.h"
#include <m-string.h>
#include <m-list.h>
#ifdef __cplusplus
@@ -21,7 +20,7 @@ typedef struct {
File* file;
StorageType type;
void* file_data;
string_t path;
FuriString* path;
} StorageFile;
typedef enum {
@@ -62,12 +61,16 @@ struct StorageData {
};
bool storage_has_file(const File* file, StorageData* storage_data);
bool storage_path_already_open(string_t path, StorageFileList_t files);
bool storage_path_already_open(FuriString* path, StorageFileList_t files);
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
void* storage_get_storage_file_data(const File* file, StorageData* storage);
void storage_push_storage_file(File* file, string_t path, StorageType type, StorageData* storage);
void storage_push_storage_file(
File* file,
FuriString* path,
StorageType type,
StorageData* storage);
bool storage_pop_storage_file(File* file, StorageData* storage);
#ifdef __cplusplus
@@ -1,5 +1,4 @@
#include <core/record.h>
#include <m-string.h>
#include "storage.h"
#include <toolbox/tar/tar_archive.h>
@@ -1,7 +1,6 @@
#include "storage_processing.h"
#include <m-list.h>
#include <m-dict.h>
#include <m-string.h>
#define FS_CALL(_storage, _fn) \
storage_data_lock(_storage); \
@@ -68,21 +67,22 @@ static StorageType storage_get_type_by_path(Storage* app, const char* path) {
return type;
}
static void storage_path_change_to_real_storage(string_t path, StorageType real_storage) {
if(memcmp(string_get_cstr(path), STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) ==
static void storage_path_change_to_real_storage(FuriString* path, StorageType real_storage) {
if(memcmp(
furi_string_get_cstr(path), STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) ==
0) {
switch(real_storage) {
case ST_EXT:
string_set_char(path, 0, STORAGE_EXT_PATH_PREFIX[0]);
string_set_char(path, 1, STORAGE_EXT_PATH_PREFIX[1]);
string_set_char(path, 2, STORAGE_EXT_PATH_PREFIX[2]);
string_set_char(path, 3, STORAGE_EXT_PATH_PREFIX[3]);
furi_string_set_char(path, 0, STORAGE_EXT_PATH_PREFIX[0]);
furi_string_set_char(path, 1, STORAGE_EXT_PATH_PREFIX[1]);
furi_string_set_char(path, 2, STORAGE_EXT_PATH_PREFIX[2]);
furi_string_set_char(path, 3, STORAGE_EXT_PATH_PREFIX[3]);
break;
case ST_INT:
string_set_char(path, 0, STORAGE_INT_PATH_PREFIX[0]);
string_set_char(path, 1, STORAGE_INT_PATH_PREFIX[1]);
string_set_char(path, 2, STORAGE_INT_PATH_PREFIX[2]);
string_set_char(path, 3, STORAGE_INT_PATH_PREFIX[3]);
furi_string_set_char(path, 0, STORAGE_INT_PATH_PREFIX[0]);
furi_string_set_char(path, 1, STORAGE_INT_PATH_PREFIX[1]);
furi_string_set_char(path, 2, STORAGE_INT_PATH_PREFIX[2]);
furi_string_set_char(path, 3, STORAGE_INT_PATH_PREFIX[3]);
break;
default:
break;
@@ -107,8 +107,8 @@ bool storage_process_file_open(
file->error_id = FSE_INVALID_NAME;
} else {
storage = storage_get_storage_by_type(app, type);
string_t real_path;
string_init_set(real_path, path);
FuriString* real_path;
real_path = furi_string_alloc_set(path);
storage_path_change_to_real_storage(real_path, type);
if(storage_path_already_open(real_path, storage->files)) {
@@ -118,7 +118,7 @@ bool storage_process_file_open(
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
}
string_clear(real_path);
furi_string_free(real_path);
}
return ret;
@@ -266,8 +266,8 @@ bool storage_process_dir_open(Storage* app, File* file, const char* path) {
file->error_id = FSE_INVALID_NAME;
} else {
storage = storage_get_storage_by_type(app, type);
string_t real_path;
string_init_set(real_path, path);
FuriString* real_path;
real_path = furi_string_alloc_set(path);
storage_path_change_to_real_storage(real_path, type);
if(storage_path_already_open(real_path, storage->files)) {
@@ -276,7 +276,7 @@ bool storage_process_dir_open(Storage* app, File* file, const char* path) {
storage_push_storage_file(file, real_path, type, storage);
FS_CALL(storage, dir.open(storage, file, remove_vfs(path)));
}
string_clear(real_path);
furi_string_free(real_path);
}
return ret;
@@ -350,8 +350,8 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
FS_Error ret = FSE_OK;
StorageType type = storage_get_type_by_path(app, path);
string_t real_path;
string_init_set(real_path, path);
FuriString* real_path;
real_path = furi_string_alloc_set(path);
storage_path_change_to_real_storage(real_path, type);
do {
@@ -369,7 +369,7 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
} while(false);
string_clear(real_path);
furi_string_free(real_path);
return ret;
}
@@ -224,13 +224,12 @@ static void do_dir_test(Storage* api, const char* path) {
}
static void do_test_start(Storage* api, const char* path) {
string_t str_path;
string_init_printf(str_path, "%s/test-folder", path);
FuriString* str_path = furi_string_alloc_printf("%s/test-folder", path);
FURI_LOG_I(TAG, "--------- START \"%s\" ---------", path);
// mkdir
FS_Error result = storage_common_mkdir(api, string_get_cstr(str_path));
FS_Error result = storage_common_mkdir(api, furi_string_get_cstr(str_path));
if(result == FSE_OK) {
FURI_LOG_I(TAG, "mkdir ok");
@@ -240,7 +239,7 @@ static void do_test_start(Storage* api, const char* path) {
// stat
FileInfo fileinfo;
result = storage_common_stat(api, string_get_cstr(str_path), &fileinfo);
result = storage_common_stat(api, furi_string_get_cstr(str_path), &fileinfo);
if(result == FSE_OK) {
if(fileinfo.flags & FSF_DIRECTORY) {
@@ -252,16 +251,14 @@ static void do_test_start(Storage* api, const char* path) {
FURI_LOG_E(TAG, "stat #1, %s", storage_error_get_desc(result));
}
string_clear(str_path);
furi_string_free(str_path);
}
static void do_test_end(Storage* api, const char* path) {
uint64_t total_space;
uint64_t free_space;
string_t str_path_1;
string_t str_path_2;
string_init_printf(str_path_1, "%s/test-folder", path);
string_init_printf(str_path_2, "%s/test-folder2", path);
FuriString* str_path_1 = furi_string_alloc_printf("%s/test-folder", path);
FuriString* str_path_2 = furi_string_alloc_printf("%s/test-folder2", path);
FURI_LOG_I(TAG, "--------- END \"%s\" ---------", path);
@@ -277,7 +274,8 @@ static void do_test_end(Storage* api, const char* path) {
}
// rename #1
result = storage_common_rename(api, string_get_cstr(str_path_1), string_get_cstr(str_path_2));
result = storage_common_rename(
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
if(result == FSE_OK) {
FURI_LOG_I(TAG, "rename #1 ok");
} else {
@@ -285,7 +283,7 @@ static void do_test_end(Storage* api, const char* path) {
}
// remove #1
result = storage_common_remove(api, string_get_cstr(str_path_2));
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
if(result == FSE_OK) {
FURI_LOG_I(TAG, "remove #1 ok");
} else {
@@ -293,10 +291,11 @@ static void do_test_end(Storage* api, const char* path) {
}
// rename #2
string_printf(str_path_1, "%s/test.txt", path);
string_printf(str_path_2, "%s/test2.txt", path);
furi_string_printf(str_path_1, "%s/test.txt", path);
furi_string_printf(str_path_2, "%s/test2.txt", path);
result = storage_common_rename(api, string_get_cstr(str_path_1), string_get_cstr(str_path_2));
result = storage_common_rename(
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
if(result == FSE_OK) {
FURI_LOG_I(TAG, "rename #2 ok");
} else {
@@ -304,15 +303,15 @@ static void do_test_end(Storage* api, const char* path) {
}
// remove #2
result = storage_common_remove(api, string_get_cstr(str_path_2));
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
if(result == FSE_OK) {
FURI_LOG_I(TAG, "remove #2 ok");
} else {
FURI_LOG_E(TAG, "remove #2, %s", storage_error_get_desc(result));
}
string_clear(str_path_1);
string_clear(str_path_2);
furi_string_free(str_path_1);
furi_string_free(str_path_2);
}
int32_t storage_test_app(void* p) {
@@ -338,11 +338,12 @@ static bool storage_int_file_open(
storage_set_storage_file_data(file, handle, storage);
if(!enough_free_space) {
string_t filename;
string_init(filename);
FuriString* filename;
filename = furi_string_alloc();
path_extract_basename(path, filename);
bool is_dot_file = (!string_empty_p(filename) && (string_get_char(filename, 0) == '.'));
string_clear(filename);
bool is_dot_file =
(!furi_string_empty(filename) && (furi_string_get_char(filename, 0) == '.'));
furi_string_free(filename);
/* Restrict write & creation access to all non-dot files */
if(!is_dot_file && (flags & (LFS_O_CREAT | LFS_O_WRONLY))) {