mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-26 14:51:52 +03:00
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:
parent
0f9ea925d3
commit
4bf29827f8
@ -3,14 +3,13 @@
|
||||
#include <gui/canvas.h>
|
||||
#include <gui/elements.h>
|
||||
#include <m-array.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct BtTestParam {
|
||||
const char* label;
|
||||
uint8_t current_value_index;
|
||||
string_t current_value_text;
|
||||
FuriString* current_value_text;
|
||||
uint8_t values_count;
|
||||
BtTestParamChangeCallback change_callback;
|
||||
void* context;
|
||||
@ -85,7 +84,8 @@ static void bt_test_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_draw_str(canvas, 50, param_text_y, "<");
|
||||
}
|
||||
|
||||
canvas_draw_str(canvas, 61, param_text_y, string_get_cstr(param->current_value_text));
|
||||
canvas_draw_str(
|
||||
canvas, 61, param_text_y, furi_string_get_cstr(param->current_value_text));
|
||||
|
||||
if(param->current_value_index < (param->values_count - 1)) {
|
||||
canvas_draw_str(canvas, 113, param_text_y, ">");
|
||||
@ -322,7 +322,7 @@ void bt_test_free(BtTest* bt_test) {
|
||||
BtTestParamArray_it_t it;
|
||||
for(BtTestParamArray_it(it, model->params); !BtTestParamArray_end_p(it);
|
||||
BtTestParamArray_next(it)) {
|
||||
string_clear(BtTestParamArray_ref(it)->current_value_text);
|
||||
furi_string_free(BtTestParamArray_ref(it)->current_value_text);
|
||||
}
|
||||
BtTestParamArray_clear(model->params);
|
||||
return false;
|
||||
@ -354,7 +354,7 @@ BtTestParam* bt_test_param_add(
|
||||
param->change_callback = change_callback;
|
||||
param->context = context;
|
||||
param->current_value_index = 0;
|
||||
string_init(param->current_value_text);
|
||||
param->current_value_text = furi_string_alloc();
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -410,7 +410,7 @@ void bt_test_set_current_value_index(BtTestParam* param, uint8_t current_value_i
|
||||
}
|
||||
|
||||
void bt_test_set_current_value_text(BtTestParam* param, const char* current_value_text) {
|
||||
string_set_str(param->current_value_text, current_value_text);
|
||||
furi_string_set(param->current_value_text, current_value_text);
|
||||
}
|
||||
|
||||
uint8_t bt_test_get_current_value_index(BtTestParam* param) {
|
||||
|
@ -113,11 +113,11 @@ static void display_config_set_regulation_ratio(VariableItem* item) {
|
||||
static void display_config_set_contrast(VariableItem* item) {
|
||||
DisplayTest* instance = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
string_t temp;
|
||||
string_init(temp);
|
||||
string_cat_printf(temp, "%d", index);
|
||||
variable_item_set_current_value_text(item, string_get_cstr(temp));
|
||||
string_clear(temp);
|
||||
FuriString* temp;
|
||||
temp = furi_string_alloc();
|
||||
furi_string_cat_printf(temp, "%d", index);
|
||||
variable_item_set_current_value_text(item, furi_string_get_cstr(temp));
|
||||
furi_string_free(temp);
|
||||
instance->config_contrast = index;
|
||||
display_test_reload_config(instance);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "assets_icons.h"
|
||||
#include "file_browser_app_i.h"
|
||||
#include "gui/modules/file_browser.h"
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
@ -47,7 +46,7 @@ FileBrowserApp* file_browser_app_alloc(char* arg) {
|
||||
|
||||
app->widget = widget_alloc();
|
||||
|
||||
string_init(app->file_path);
|
||||
app->file_path = furi_string_alloc();
|
||||
app->file_browser = file_browser_alloc(app->file_path);
|
||||
file_browser_configure(app->file_browser, "*", true, &I_badusb_10px, true);
|
||||
|
||||
@ -84,7 +83,7 @@ void file_browser_app_free(FileBrowserApp* app) {
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
|
||||
string_clear(app->file_path);
|
||||
furi_string_free(app->file_path);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ struct FileBrowserApp {
|
||||
Widget* widget;
|
||||
FileBrowser* file_browser;
|
||||
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include "../file_browser_app_i.h"
|
||||
#include <core/check.h>
|
||||
#include <core/log.h>
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
|
||||
#define DEFAULT_PATH "/"
|
||||
#define EXTENSION "*"
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "../file_browser_app_i.h"
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
|
||||
void file_browser_scene_result_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
@ -24,7 +23,13 @@ void file_browser_scene_result_on_enter(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
app->widget, 64, 10, AlignCenter, AlignTop, FontSecondary, string_get_cstr(app->file_path));
|
||||
app->widget,
|
||||
64,
|
||||
10,
|
||||
AlignCenter,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
furi_string_get_cstr(app->file_path));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewResult);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ bool file_browser_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
string_set_str(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
|
||||
furi_string_set(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
|
||||
scene_manager_next_scene(app->scene_manager, FileBrowserSceneBrowser);
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <furi.h>
|
||||
#include <m-string.h>
|
||||
#include <gui/gui.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
@ -25,7 +24,7 @@ typedef struct {
|
||||
} UartEchoApp;
|
||||
|
||||
typedef struct {
|
||||
string_t text;
|
||||
FuriString* text;
|
||||
} ListElement;
|
||||
|
||||
struct UartDumpModel {
|
||||
@ -64,10 +63,11 @@ static void uart_echo_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas,
|
||||
0,
|
||||
(i + 1) * (canvas_current_font_height(canvas) - 1),
|
||||
string_get_cstr(model->list[i]->text));
|
||||
furi_string_get_cstr(model->list[i]->text));
|
||||
|
||||
if(i == model->line) {
|
||||
uint8_t width = canvas_string_width(canvas, string_get_cstr(model->list[i]->text));
|
||||
uint8_t width =
|
||||
canvas_string_width(canvas, furi_string_get_cstr(model->list[i]->text));
|
||||
|
||||
canvas_draw_box(
|
||||
canvas,
|
||||
@ -113,7 +113,7 @@ static void uart_echo_push_to_list(UartDumpModel* model, const char data) {
|
||||
model->escape = true;
|
||||
} else if((data >= ' ' && data <= '~') || (data == '\n' || data == '\r')) {
|
||||
bool new_string_needed = false;
|
||||
if(string_size(model->list[model->line]->text) >= COLUMNS_ON_SCREEN) {
|
||||
if(furi_string_size(model->list[model->line]->text) >= COLUMNS_ON_SCREEN) {
|
||||
new_string_needed = true;
|
||||
} else if((data == '\n' || data == '\r')) {
|
||||
// pack line breaks
|
||||
@ -132,13 +132,13 @@ static void uart_echo_push_to_list(UartDumpModel* model, const char data) {
|
||||
model->list[i - 1] = model->list[i];
|
||||
}
|
||||
|
||||
string_reset(first->text);
|
||||
furi_string_reset(first->text);
|
||||
model->list[model->line] = first;
|
||||
}
|
||||
}
|
||||
|
||||
if(data != '\n' && data != '\r') {
|
||||
string_push_back(model->list[model->line]->text, data);
|
||||
furi_string_push_back(model->list[model->line]->text, data);
|
||||
}
|
||||
}
|
||||
model->last_char = data;
|
||||
@ -208,7 +208,7 @@ static UartEchoApp* uart_echo_app_alloc() {
|
||||
model->line = 0;
|
||||
model->escape = false;
|
||||
model->list[i] = malloc(sizeof(ListElement));
|
||||
string_init(model->list[i]->text);
|
||||
model->list[i]->text = furi_string_alloc();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@ -247,7 +247,7 @@ static void uart_echo_app_free(UartEchoApp* app) {
|
||||
with_view_model(
|
||||
app->view, (UartDumpModel * model) {
|
||||
for(size_t i = 0; i < LINES_ON_SCREEN; i++) {
|
||||
string_clear(model->list[i]->text);
|
||||
furi_string_free(model->list[i]->text);
|
||||
free(model->list[i]);
|
||||
}
|
||||
return true;
|
||||
|
@ -58,7 +58,7 @@ static const char* test_data_win = "Filetype: Flipper Format test\r\n"
|
||||
#define ARRAY_W_BSIZE(x) (x), (sizeof(x))
|
||||
|
||||
MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
string_t tmpstr;
|
||||
FuriString* tmpstr;
|
||||
uint32_t version;
|
||||
uint32_t uint32_data[COUNT_OF(test_uint_data)];
|
||||
int32_t int32_data[COUNT_OF(test_int_data)];
|
||||
@ -101,14 +101,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
mu_assert_int_eq(position_before, stream_tell(flipper_format_get_raw_stream(flipper_format)));
|
||||
|
||||
// read test
|
||||
string_init(tmpstr);
|
||||
tmpstr = furi_string_alloc();
|
||||
|
||||
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
|
||||
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
|
||||
mu_assert_int_eq(test_version, version);
|
||||
|
||||
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
|
||||
mu_assert_string_eq(test_string_data, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_string_data, furi_string_get_cstr(tmpstr));
|
||||
|
||||
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
|
||||
mu_assert_int_eq(COUNT_OF(test_int_data), count);
|
||||
@ -133,7 +133,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
|
||||
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
|
||||
|
||||
string_clear(tmpstr);
|
||||
furi_string_free(tmpstr);
|
||||
|
||||
// update data
|
||||
mu_check(flipper_format_rewind(flipper_format));
|
||||
@ -155,14 +155,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
uint8_t hex_updated_data[COUNT_OF(test_hex_updated_data)];
|
||||
|
||||
mu_check(flipper_format_rewind(flipper_format));
|
||||
string_init(tmpstr);
|
||||
tmpstr = furi_string_alloc();
|
||||
|
||||
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
|
||||
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
|
||||
mu_assert_int_eq(test_version, version);
|
||||
|
||||
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
|
||||
mu_assert_string_eq(test_string_updated_data, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_string_updated_data, furi_string_get_cstr(tmpstr));
|
||||
|
||||
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
|
||||
mu_assert_int_eq(COUNT_OF(test_int_updated_data), count);
|
||||
@ -190,7 +190,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
|
||||
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
|
||||
|
||||
string_clear(tmpstr);
|
||||
furi_string_free(tmpstr);
|
||||
|
||||
// update data
|
||||
mu_check(flipper_format_rewind(flipper_format));
|
||||
@ -214,14 +214,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
uint8_t hex_new_data[COUNT_OF(test_hex_new_data)];
|
||||
|
||||
mu_check(flipper_format_rewind(flipper_format));
|
||||
string_init(tmpstr);
|
||||
tmpstr = furi_string_alloc();
|
||||
|
||||
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
|
||||
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
|
||||
mu_assert_int_eq(test_version, version);
|
||||
|
||||
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
|
||||
mu_assert_string_eq(test_string_updated_2_data, string_get_cstr(tmpstr));
|
||||
mu_assert_string_eq(test_string_updated_2_data, furi_string_get_cstr(tmpstr));
|
||||
|
||||
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
|
||||
mu_assert_int_eq(COUNT_OF(test_int_updated_2_data), count);
|
||||
@ -255,7 +255,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
|
||||
|
||||
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
|
||||
|
||||
string_clear(tmpstr);
|
||||
furi_string_free(tmpstr);
|
||||
|
||||
// delete key test
|
||||
mu_check(flipper_format_rewind(flipper_format));
|
||||
|
@ -102,8 +102,8 @@ static bool test_read(const char* file_name) {
|
||||
bool result = false;
|
||||
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
string_t string_value;
|
||||
string_init(string_value);
|
||||
FuriString* string_value;
|
||||
string_value = furi_string_alloc();
|
||||
uint32_t uint32_value;
|
||||
void* scratchpad = malloc(512);
|
||||
|
||||
@ -111,11 +111,11 @@ static bool test_read(const char* file_name) {
|
||||
if(!flipper_format_file_open_existing(file, file_name)) break;
|
||||
|
||||
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
|
||||
if(string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(uint32_value != test_version) break;
|
||||
|
||||
if(!flipper_format_read_string(file, test_string_key, string_value)) break;
|
||||
if(string_cmp_str(string_value, test_string_data) != 0) break;
|
||||
if(furi_string_cmp_str(string_value, test_string_data) != 0) break;
|
||||
|
||||
if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
|
||||
if(uint32_value != COUNT_OF(test_int_data)) break;
|
||||
@ -150,7 +150,7 @@ static bool test_read(const char* file_name) {
|
||||
} while(false);
|
||||
|
||||
free(scratchpad);
|
||||
string_clear(string_value);
|
||||
furi_string_free(string_value);
|
||||
|
||||
flipper_format_free(file);
|
||||
|
||||
@ -164,8 +164,8 @@ static bool test_read_updated(const char* file_name) {
|
||||
bool result = false;
|
||||
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
string_t string_value;
|
||||
string_init(string_value);
|
||||
FuriString* string_value;
|
||||
string_value = furi_string_alloc();
|
||||
uint32_t uint32_value;
|
||||
void* scratchpad = malloc(512);
|
||||
|
||||
@ -173,11 +173,11 @@ static bool test_read_updated(const char* file_name) {
|
||||
if(!flipper_format_file_open_existing(file, file_name)) break;
|
||||
|
||||
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
|
||||
if(string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(uint32_value != test_version) break;
|
||||
|
||||
if(!flipper_format_read_string(file, test_string_key, string_value)) break;
|
||||
if(string_cmp_str(string_value, test_string_updated_data) != 0) break;
|
||||
if(furi_string_cmp_str(string_value, test_string_updated_data) != 0) break;
|
||||
|
||||
if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
|
||||
if(uint32_value != COUNT_OF(test_int_updated_data)) break;
|
||||
@ -228,7 +228,7 @@ static bool test_read_updated(const char* file_name) {
|
||||
} while(false);
|
||||
|
||||
free(scratchpad);
|
||||
string_clear(string_value);
|
||||
furi_string_free(string_value);
|
||||
|
||||
flipper_format_free(file);
|
||||
|
||||
@ -401,14 +401,14 @@ static bool test_read_multikey(const char* file_name) {
|
||||
bool result = false;
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
|
||||
string_t string_value;
|
||||
string_init(string_value);
|
||||
FuriString* string_value;
|
||||
string_value = furi_string_alloc();
|
||||
uint32_t uint32_value;
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(file, file_name)) break;
|
||||
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
|
||||
if(string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
|
||||
if(uint32_value != test_version) break;
|
||||
|
||||
bool error = false;
|
||||
@ -429,7 +429,7 @@ static bool test_read_multikey(const char* file_name) {
|
||||
result = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(string_value);
|
||||
furi_string_free(string_value);
|
||||
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
469
applications/debug/unit_tests/furi/furi_string_test.c
Normal file
469
applications/debug/unit_tests/furi/furi_string_test.c
Normal file
@ -0,0 +1,469 @@
|
||||
#include <furi.h>
|
||||
#include "../minunit.h"
|
||||
|
||||
static void test_setup(void) {
|
||||
}
|
||||
|
||||
static void test_teardown(void) {
|
||||
}
|
||||
|
||||
static FuriString* furi_string_alloc_vprintf_test(const char format[], ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
FuriString* string = furi_string_alloc_vprintf(format, args);
|
||||
va_end(args);
|
||||
return string;
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_alloc_free) {
|
||||
FuriString* tmp;
|
||||
FuriString* string;
|
||||
|
||||
// test alloc and free
|
||||
string = furi_string_alloc();
|
||||
mu_check(string != NULL);
|
||||
mu_check(furi_string_empty(string));
|
||||
furi_string_free(string);
|
||||
|
||||
// test furi_string_alloc_set_str and free
|
||||
string = furi_string_alloc_set_str("test");
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
mu_check(furi_string_cmp(string, "test") == 0);
|
||||
furi_string_free(string);
|
||||
|
||||
// test furi_string_alloc_set and free
|
||||
tmp = furi_string_alloc_set("more");
|
||||
string = furi_string_alloc_set(tmp);
|
||||
furi_string_free(tmp);
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
mu_check(furi_string_cmp(string, "more") == 0);
|
||||
furi_string_free(string);
|
||||
|
||||
// test alloc_printf and free
|
||||
string = furi_string_alloc_printf("test %d %s %c 0x%02x", 1, "two", '3', 0x04);
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
mu_check(furi_string_cmp(string, "test 1 two 3 0x04") == 0);
|
||||
furi_string_free(string);
|
||||
|
||||
// test alloc_vprintf and free
|
||||
string = furi_string_alloc_vprintf_test("test %d %s %c 0x%02x", 4, "five", '6', 0x07);
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
mu_check(furi_string_cmp(string, "test 4 five 6 0x07") == 0);
|
||||
furi_string_free(string);
|
||||
|
||||
// test alloc_move and free
|
||||
tmp = furi_string_alloc_set("move");
|
||||
string = furi_string_alloc_move(tmp);
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
mu_check(furi_string_cmp(string, "move") == 0);
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_mem) {
|
||||
FuriString* string = furi_string_alloc_set("test");
|
||||
mu_check(string != NULL);
|
||||
mu_check(!furi_string_empty(string));
|
||||
|
||||
// TODO: how to test furi_string_reserve?
|
||||
|
||||
// test furi_string_reset
|
||||
furi_string_reset(string);
|
||||
mu_check(furi_string_empty(string));
|
||||
|
||||
// test furi_string_swap
|
||||
furi_string_set(string, "test");
|
||||
FuriString* swap_string = furi_string_alloc_set("swap");
|
||||
furi_string_swap(string, swap_string);
|
||||
mu_check(furi_string_cmp(string, "swap") == 0);
|
||||
mu_check(furi_string_cmp(swap_string, "test") == 0);
|
||||
furi_string_free(swap_string);
|
||||
|
||||
// test furi_string_move
|
||||
FuriString* move_string = furi_string_alloc_set("move");
|
||||
furi_string_move(string, move_string);
|
||||
mu_check(furi_string_cmp(string, "move") == 0);
|
||||
// move_string is now empty
|
||||
// and tested by leaked memory check at the end of the tests
|
||||
|
||||
furi_string_set(string, "abracadabra");
|
||||
|
||||
// test furi_string_hash
|
||||
mu_assert_int_eq(0xc3bc16d7, furi_string_hash(string));
|
||||
|
||||
// test furi_string_size
|
||||
mu_assert_int_eq(11, furi_string_size(string));
|
||||
|
||||
// test furi_string_empty
|
||||
mu_check(!furi_string_empty(string));
|
||||
furi_string_reset(string);
|
||||
mu_check(furi_string_empty(string));
|
||||
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_getters) {
|
||||
FuriString* string = furi_string_alloc_set("test");
|
||||
|
||||
// test furi_string_get_char
|
||||
mu_check(furi_string_get_char(string, 0) == 't');
|
||||
mu_check(furi_string_get_char(string, 1) == 'e');
|
||||
mu_check(furi_string_get_char(string, 2) == 's');
|
||||
mu_check(furi_string_get_char(string, 3) == 't');
|
||||
|
||||
// test furi_string_get_cstr
|
||||
mu_assert_string_eq("test", furi_string_get_cstr(string));
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
static FuriString* furi_string_vprintf_test(FuriString* string, const char format[], ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
furi_string_vprintf(string, format, args);
|
||||
va_end(args);
|
||||
return string;
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_setters) {
|
||||
FuriString* tmp;
|
||||
FuriString* string = furi_string_alloc();
|
||||
|
||||
// test furi_string_set_str
|
||||
furi_string_set_str(string, "test");
|
||||
mu_assert_string_eq("test", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_set
|
||||
tmp = furi_string_alloc_set("more");
|
||||
furi_string_set(string, tmp);
|
||||
furi_string_free(tmp);
|
||||
mu_assert_string_eq("more", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_set_strn
|
||||
furi_string_set_strn(string, "test", 2);
|
||||
mu_assert_string_eq("te", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_set_char
|
||||
furi_string_set_char(string, 0, 'a');
|
||||
furi_string_set_char(string, 1, 'b');
|
||||
mu_assert_string_eq("ab", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_set_n
|
||||
tmp = furi_string_alloc_set("dodecahedron");
|
||||
furi_string_set_n(string, tmp, 4, 5);
|
||||
furi_string_free(tmp);
|
||||
mu_assert_string_eq("cahed", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_printf
|
||||
furi_string_printf(string, "test %d %s %c 0x%02x", 1, "two", '3', 0x04);
|
||||
mu_assert_string_eq("test 1 two 3 0x04", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_vprintf
|
||||
furi_string_vprintf_test(string, "test %d %s %c 0x%02x", 4, "five", '6', 0x07);
|
||||
mu_assert_string_eq("test 4 five 6 0x07", furi_string_get_cstr(string));
|
||||
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
static FuriString* furi_string_cat_vprintf_test(FuriString* string, const char format[], ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
furi_string_cat_vprintf(string, format, args);
|
||||
va_end(args);
|
||||
return string;
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_appends) {
|
||||
FuriString* tmp;
|
||||
FuriString* string = furi_string_alloc();
|
||||
|
||||
// test furi_string_push_back
|
||||
furi_string_push_back(string, 't');
|
||||
furi_string_push_back(string, 'e');
|
||||
furi_string_push_back(string, 's');
|
||||
furi_string_push_back(string, 't');
|
||||
mu_assert_string_eq("test", furi_string_get_cstr(string));
|
||||
furi_string_push_back(string, '!');
|
||||
mu_assert_string_eq("test!", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_cat_str
|
||||
furi_string_cat_str(string, "test");
|
||||
mu_assert_string_eq("test!test", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_cat
|
||||
tmp = furi_string_alloc_set("more");
|
||||
furi_string_cat(string, tmp);
|
||||
furi_string_free(tmp);
|
||||
mu_assert_string_eq("test!testmore", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_cat_printf
|
||||
furi_string_cat_printf(string, "test %d %s %c 0x%02x", 1, "two", '3', 0x04);
|
||||
mu_assert_string_eq("test!testmoretest 1 two 3 0x04", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_cat_vprintf
|
||||
furi_string_cat_vprintf_test(string, "test %d %s %c 0x%02x", 4, "five", '6', 0x07);
|
||||
mu_assert_string_eq(
|
||||
"test!testmoretest 1 two 3 0x04test 4 five 6 0x07", furi_string_get_cstr(string));
|
||||
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_compare) {
|
||||
FuriString* string_1 = furi_string_alloc_set("string_1");
|
||||
FuriString* string_2 = furi_string_alloc_set("string_2");
|
||||
|
||||
// test furi_string_cmp
|
||||
mu_assert_int_eq(0, furi_string_cmp(string_1, string_1));
|
||||
mu_assert_int_eq(0, furi_string_cmp(string_2, string_2));
|
||||
mu_assert_int_eq(-1, furi_string_cmp(string_1, string_2));
|
||||
mu_assert_int_eq(1, furi_string_cmp(string_2, string_1));
|
||||
|
||||
// test furi_string_cmp_str
|
||||
mu_assert_int_eq(0, furi_string_cmp_str(string_1, "string_1"));
|
||||
mu_assert_int_eq(0, furi_string_cmp_str(string_2, "string_2"));
|
||||
mu_assert_int_eq(-1, furi_string_cmp_str(string_1, "string_2"));
|
||||
mu_assert_int_eq(1, furi_string_cmp_str(string_2, "string_1"));
|
||||
|
||||
// test furi_string_cmpi
|
||||
furi_string_set(string_1, "string");
|
||||
furi_string_set(string_2, "StrIng");
|
||||
mu_assert_int_eq(0, furi_string_cmpi(string_1, string_1));
|
||||
mu_assert_int_eq(0, furi_string_cmpi(string_2, string_2));
|
||||
mu_assert_int_eq(0, furi_string_cmpi(string_1, string_2));
|
||||
mu_assert_int_eq(0, furi_string_cmpi(string_2, string_1));
|
||||
furi_string_set(string_1, "string_1");
|
||||
furi_string_set(string_2, "StrIng_2");
|
||||
mu_assert_int_eq(32, furi_string_cmp(string_1, string_2));
|
||||
mu_assert_int_eq(-32, furi_string_cmp(string_2, string_1));
|
||||
mu_assert_int_eq(-1, furi_string_cmpi(string_1, string_2));
|
||||
mu_assert_int_eq(1, furi_string_cmpi(string_2, string_1));
|
||||
|
||||
// test furi_string_cmpi_str
|
||||
furi_string_set(string_1, "string");
|
||||
mu_assert_int_eq(0, furi_string_cmp_str(string_1, "string"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "String"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STring"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRing"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRIng"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRINg"));
|
||||
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRING"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "string"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "String"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STring"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRing"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRIng"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRINg"));
|
||||
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRING"));
|
||||
|
||||
furi_string_free(string_1);
|
||||
furi_string_free(string_2);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_search) {
|
||||
// 012345678901234567
|
||||
FuriString* haystack = furi_string_alloc_set("test321test123test");
|
||||
FuriString* needle = furi_string_alloc_set("test");
|
||||
|
||||
// test furi_string_search
|
||||
mu_assert_int_eq(0, furi_string_search(haystack, needle));
|
||||
mu_assert_int_eq(7, furi_string_search(haystack, needle, 1));
|
||||
mu_assert_int_eq(14, furi_string_search(haystack, needle, 8));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search(haystack, needle, 15));
|
||||
|
||||
FuriString* tmp = furi_string_alloc_set("testnone");
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search(haystack, tmp));
|
||||
furi_string_free(tmp);
|
||||
|
||||
// test furi_string_search_str
|
||||
mu_assert_int_eq(0, furi_string_search_str(haystack, "test"));
|
||||
mu_assert_int_eq(7, furi_string_search_str(haystack, "test", 1));
|
||||
mu_assert_int_eq(14, furi_string_search_str(haystack, "test", 8));
|
||||
mu_assert_int_eq(4, furi_string_search_str(haystack, "321"));
|
||||
mu_assert_int_eq(11, furi_string_search_str(haystack, "123"));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_str(haystack, "testnone"));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_str(haystack, "test", 15));
|
||||
|
||||
// test furi_string_search_char
|
||||
mu_assert_int_eq(0, furi_string_search_char(haystack, 't'));
|
||||
mu_assert_int_eq(1, furi_string_search_char(haystack, 'e'));
|
||||
mu_assert_int_eq(2, furi_string_search_char(haystack, 's'));
|
||||
mu_assert_int_eq(3, furi_string_search_char(haystack, 't', 1));
|
||||
mu_assert_int_eq(7, furi_string_search_char(haystack, 't', 4));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_char(haystack, 'x'));
|
||||
|
||||
// test furi_string_search_rchar
|
||||
mu_assert_int_eq(17, furi_string_search_rchar(haystack, 't'));
|
||||
mu_assert_int_eq(15, furi_string_search_rchar(haystack, 'e'));
|
||||
mu_assert_int_eq(16, furi_string_search_rchar(haystack, 's'));
|
||||
mu_assert_int_eq(13, furi_string_search_rchar(haystack, '3'));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_rchar(haystack, '3', 14));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_rchar(haystack, 'x'));
|
||||
|
||||
furi_string_free(haystack);
|
||||
furi_string_free(needle);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_equality) {
|
||||
FuriString* string = furi_string_alloc_set("test");
|
||||
FuriString* string_eq = furi_string_alloc_set("test");
|
||||
FuriString* string_neq = furi_string_alloc_set("test2");
|
||||
|
||||
// test furi_string_equal
|
||||
mu_check(furi_string_equal(string, string_eq));
|
||||
mu_check(!furi_string_equal(string, string_neq));
|
||||
|
||||
// test furi_string_equal_str
|
||||
mu_check(furi_string_equal_str(string, "test"));
|
||||
mu_check(!furi_string_equal_str(string, "test2"));
|
||||
mu_check(furi_string_equal_str(string_neq, "test2"));
|
||||
mu_check(!furi_string_equal_str(string_neq, "test"));
|
||||
|
||||
furi_string_free(string);
|
||||
furi_string_free(string_eq);
|
||||
furi_string_free(string_neq);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_replace) {
|
||||
FuriString* needle = furi_string_alloc_set("test");
|
||||
FuriString* replace = furi_string_alloc_set("replace");
|
||||
FuriString* string = furi_string_alloc_set("test123test");
|
||||
|
||||
// test furi_string_replace_at
|
||||
furi_string_replace_at(string, 4, 3, "!biglongword!");
|
||||
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_replace
|
||||
mu_assert_int_eq(17, furi_string_replace(string, needle, replace, 1));
|
||||
mu_assert_string_eq("test!biglongword!replace", furi_string_get_cstr(string));
|
||||
mu_assert_int_eq(0, furi_string_replace(string, needle, replace));
|
||||
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_replace(string, needle, replace));
|
||||
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_replace_str
|
||||
mu_assert_int_eq(20, furi_string_replace_str(string, "replace", "test", 1));
|
||||
mu_assert_string_eq("replace!biglongword!test", furi_string_get_cstr(string));
|
||||
mu_assert_int_eq(0, furi_string_replace_str(string, "replace", "test"));
|
||||
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
|
||||
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_replace_str(string, "replace", "test"));
|
||||
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_replace_all
|
||||
furi_string_replace_all(string, needle, replace);
|
||||
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_replace_all_str
|
||||
furi_string_replace_all_str(string, "replace", "test");
|
||||
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
|
||||
|
||||
furi_string_free(string);
|
||||
furi_string_free(needle);
|
||||
furi_string_free(replace);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_start_end) {
|
||||
FuriString* string = furi_string_alloc_set("start_end");
|
||||
FuriString* start = furi_string_alloc_set("start");
|
||||
FuriString* end = furi_string_alloc_set("end");
|
||||
|
||||
// test furi_string_start_with
|
||||
mu_check(furi_string_start_with(string, start));
|
||||
mu_check(!furi_string_start_with(string, end));
|
||||
|
||||
// test furi_string_start_with_str
|
||||
mu_check(furi_string_start_with_str(string, "start"));
|
||||
mu_check(!furi_string_start_with_str(string, "end"));
|
||||
|
||||
// test furi_string_end_with
|
||||
mu_check(furi_string_end_with(string, end));
|
||||
mu_check(!furi_string_end_with(string, start));
|
||||
|
||||
// test furi_string_end_with_str
|
||||
mu_check(furi_string_end_with_str(string, "end"));
|
||||
mu_check(!furi_string_end_with_str(string, "start"));
|
||||
|
||||
furi_string_free(string);
|
||||
furi_string_free(start);
|
||||
furi_string_free(end);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_trim) {
|
||||
FuriString* string = furi_string_alloc_set("biglongstring");
|
||||
|
||||
// test furi_string_left
|
||||
furi_string_left(string, 7);
|
||||
mu_assert_string_eq("biglong", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_right
|
||||
furi_string_right(string, 3);
|
||||
mu_assert_string_eq("long", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_mid
|
||||
furi_string_mid(string, 1, 2);
|
||||
mu_assert_string_eq("on", furi_string_get_cstr(string));
|
||||
|
||||
// test furi_string_trim
|
||||
furi_string_set(string, " \n\r\tbiglongstring \n\r\t ");
|
||||
furi_string_trim(string);
|
||||
mu_assert_string_eq("biglongstring", furi_string_get_cstr(string));
|
||||
furi_string_set(string, "aaaabaaaabbaaabaaaabbtestaaaaaabbaaabaababaa");
|
||||
furi_string_trim(string, "ab");
|
||||
mu_assert_string_eq("test", furi_string_get_cstr(string));
|
||||
|
||||
furi_string_free(string);
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_string_utf8) {
|
||||
FuriString* utf8_string = furi_string_alloc_set("イルカ");
|
||||
|
||||
// test furi_string_utf8_length
|
||||
mu_assert_int_eq(9, furi_string_size(utf8_string));
|
||||
mu_assert_int_eq(3, furi_string_utf8_length(utf8_string));
|
||||
|
||||
// test furi_string_utf8_decode
|
||||
const uint8_t dolphin_emoji_array[4] = {0xF0, 0x9F, 0x90, 0xAC};
|
||||
FuriStringUTF8State state = FuriStringUTF8StateStarting;
|
||||
FuriStringUnicodeValue value = 0;
|
||||
furi_string_utf8_decode(dolphin_emoji_array[0], &state, &value);
|
||||
mu_assert_int_eq(FuriStringUTF8StateDecoding3, state);
|
||||
furi_string_utf8_decode(dolphin_emoji_array[1], &state, &value);
|
||||
mu_assert_int_eq(FuriStringUTF8StateDecoding2, state);
|
||||
furi_string_utf8_decode(dolphin_emoji_array[2], &state, &value);
|
||||
mu_assert_int_eq(FuriStringUTF8StateDecoding1, state);
|
||||
furi_string_utf8_decode(dolphin_emoji_array[3], &state, &value);
|
||||
mu_assert_int_eq(FuriStringUTF8StateStarting, state);
|
||||
mu_assert_int_eq(0x1F42C, value);
|
||||
|
||||
// test furi_string_utf8_push
|
||||
furi_string_set(utf8_string, "");
|
||||
furi_string_utf8_push(utf8_string, value);
|
||||
mu_assert_string_eq("🐬", furi_string_get_cstr(utf8_string));
|
||||
|
||||
furi_string_free(utf8_string);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
|
||||
MU_RUN_TEST(mu_test_furi_string_alloc_free);
|
||||
MU_RUN_TEST(mu_test_furi_string_mem);
|
||||
MU_RUN_TEST(mu_test_furi_string_getters);
|
||||
MU_RUN_TEST(mu_test_furi_string_setters);
|
||||
MU_RUN_TEST(mu_test_furi_string_appends);
|
||||
MU_RUN_TEST(mu_test_furi_string_compare);
|
||||
MU_RUN_TEST(mu_test_furi_string_search);
|
||||
MU_RUN_TEST(mu_test_furi_string_equality);
|
||||
MU_RUN_TEST(mu_test_furi_string_replace);
|
||||
MU_RUN_TEST(mu_test_furi_string_start_end);
|
||||
MU_RUN_TEST(mu_test_furi_string_trim);
|
||||
MU_RUN_TEST(mu_test_furi_string_utf8);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi_string() {
|
||||
MU_RUN_SUITE(test_suite);
|
||||
|
||||
return MU_EXIT_CODE;
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
typedef struct {
|
||||
InfraredDecoderHandler* decoder_handler;
|
||||
InfraredEncoderHandler* encoder_handler;
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
FlipperFormat* ff;
|
||||
} InfraredTest;
|
||||
|
||||
@ -23,7 +23,7 @@ static void infrared_test_alloc() {
|
||||
test->decoder_handler = infrared_alloc_decoder();
|
||||
test->encoder_handler = infrared_alloc_encoder();
|
||||
test->ff = flipper_format_buffered_file_alloc(storage);
|
||||
string_init(test->file_path);
|
||||
test->file_path = furi_string_alloc();
|
||||
}
|
||||
|
||||
static void infrared_test_free() {
|
||||
@ -31,18 +31,18 @@ static void infrared_test_free() {
|
||||
infrared_free_decoder(test->decoder_handler);
|
||||
infrared_free_encoder(test->encoder_handler);
|
||||
flipper_format_free(test->ff);
|
||||
string_clear(test->file_path);
|
||||
furi_string_free(test->file_path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
free(test);
|
||||
test = NULL;
|
||||
}
|
||||
|
||||
static bool infrared_test_prepare_file(const char* protocol_name) {
|
||||
string_t file_type;
|
||||
string_init(file_type);
|
||||
FuriString* file_type;
|
||||
file_type = furi_string_alloc();
|
||||
bool success = false;
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
test->file_path,
|
||||
"%s%s%s%s",
|
||||
IR_TEST_FILES_DIR,
|
||||
@ -52,14 +52,15 @@ static bool infrared_test_prepare_file(const char* protocol_name) {
|
||||
|
||||
do {
|
||||
uint32_t format_version;
|
||||
if(!flipper_format_buffered_file_open_existing(test->ff, string_get_cstr(test->file_path)))
|
||||
if(!flipper_format_buffered_file_open_existing(
|
||||
test->ff, furi_string_get_cstr(test->file_path)))
|
||||
break;
|
||||
if(!flipper_format_read_header(test->ff, file_type, &format_version)) break;
|
||||
if(string_cmp_str(file_type, "IR tests file") || format_version != 1) break;
|
||||
if(furi_string_cmp_str(file_type, "IR tests file") || format_version != 1) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(file_type);
|
||||
furi_string_free(file_type);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -68,18 +69,18 @@ static bool infrared_test_load_raw_signal(
|
||||
const char* signal_name,
|
||||
uint32_t** timings,
|
||||
uint32_t* timings_count) {
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
bool is_name_found = false;
|
||||
for(; !is_name_found && flipper_format_read_string(ff, "name", buf);
|
||||
is_name_found = !string_cmp_str(buf, signal_name))
|
||||
is_name_found = !furi_string_cmp(buf, signal_name))
|
||||
;
|
||||
|
||||
if(!is_name_found) break;
|
||||
if(!flipper_format_read_string(ff, "type", buf) || string_cmp_str(buf, "raw")) break;
|
||||
if(!flipper_format_read_string(ff, "type", buf) || furi_string_cmp_str(buf, "raw")) break;
|
||||
if(!flipper_format_get_value_count(ff, "data", timings_count)) break;
|
||||
if(!*timings_count) break;
|
||||
|
||||
@ -91,18 +92,18 @@ static bool infrared_test_load_raw_signal(
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool infrared_test_read_message(FlipperFormat* ff, InfraredMessage* message) {
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!flipper_format_read_string(ff, "protocol", buf)) break;
|
||||
message->protocol = infrared_get_protocol_by_name(string_get_cstr(buf));
|
||||
message->protocol = infrared_get_protocol_by_name(furi_string_get_cstr(buf));
|
||||
if(!infrared_is_protocol_valid(message->protocol)) break;
|
||||
if(!flipper_format_read_hex(ff, "address", (uint8_t*)&message->address, sizeof(uint32_t)))
|
||||
break;
|
||||
@ -112,7 +113,7 @@ static bool infrared_test_read_message(FlipperFormat* ff, InfraredMessage* messa
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -121,18 +122,19 @@ static bool infrared_test_load_messages(
|
||||
const char* signal_name,
|
||||
InfraredMessage** messages,
|
||||
uint32_t* messages_count) {
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
bool is_name_found = false;
|
||||
for(; !is_name_found && flipper_format_read_string(ff, "name", buf);
|
||||
is_name_found = !string_cmp_str(buf, signal_name))
|
||||
is_name_found = !furi_string_cmp(buf, signal_name))
|
||||
;
|
||||
|
||||
if(!is_name_found) break;
|
||||
if(!flipper_format_read_string(ff, "type", buf) || string_cmp_str(buf, "parsed_array"))
|
||||
if(!flipper_format_read_string(ff, "type", buf) ||
|
||||
furi_string_cmp_str(buf, "parsed_array"))
|
||||
break;
|
||||
if(!flipper_format_read_uint32(ff, "count", messages_count, 1)) break;
|
||||
if(!*messages_count) break;
|
||||
@ -151,7 +153,7 @@ static bool infrared_test_load_messages(
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -213,26 +215,26 @@ static void infrared_test_run_encoder(InfraredProtocol protocol, uint32_t test_i
|
||||
InfraredMessage* input_messages;
|
||||
uint32_t input_messages_count;
|
||||
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
|
||||
const char* protocol_name = infrared_get_protocol_name(protocol);
|
||||
mu_assert(infrared_test_prepare_file(protocol_name), "Failed to prepare test file");
|
||||
|
||||
string_printf(buf, "encoder_input%d", test_index);
|
||||
furi_string_printf(buf, "encoder_input%d", test_index);
|
||||
mu_assert(
|
||||
infrared_test_load_messages(
|
||||
test->ff, string_get_cstr(buf), &input_messages, &input_messages_count),
|
||||
test->ff, furi_string_get_cstr(buf), &input_messages, &input_messages_count),
|
||||
"Failed to load messages from file");
|
||||
|
||||
string_printf(buf, "encoder_expected%d", test_index);
|
||||
furi_string_printf(buf, "encoder_expected%d", test_index);
|
||||
mu_assert(
|
||||
infrared_test_load_raw_signal(
|
||||
test->ff, string_get_cstr(buf), &expected_timings, &expected_timings_count),
|
||||
test->ff, furi_string_get_cstr(buf), &expected_timings, &expected_timings_count),
|
||||
"Failed to load raw signal from file");
|
||||
|
||||
flipper_format_buffered_file_close(test->ff);
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
|
||||
uint32_t j = 0;
|
||||
timings = malloc(sizeof(uint32_t) * timings_count);
|
||||
@ -267,22 +269,22 @@ static void infrared_test_run_encoder_decoder(InfraredProtocol protocol, uint32_
|
||||
uint32_t input_messages_count;
|
||||
bool level = false;
|
||||
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
|
||||
timings = malloc(sizeof(uint32_t) * timings_count);
|
||||
|
||||
const char* protocol_name = infrared_get_protocol_name(protocol);
|
||||
mu_assert(infrared_test_prepare_file(protocol_name), "Failed to prepare test file");
|
||||
|
||||
string_printf(buf, "encoder_decoder_input%d", test_index);
|
||||
furi_string_printf(buf, "encoder_decoder_input%d", test_index);
|
||||
mu_assert(
|
||||
infrared_test_load_messages(
|
||||
test->ff, string_get_cstr(buf), &input_messages, &input_messages_count),
|
||||
test->ff, furi_string_get_cstr(buf), &input_messages, &input_messages_count),
|
||||
"Failed to load messages from file");
|
||||
|
||||
flipper_format_buffered_file_close(test->ff);
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
|
||||
for(uint32_t message_counter = 0; message_counter < input_messages_count; ++message_counter) {
|
||||
const InfraredMessage* message_encoded = &input_messages[message_counter];
|
||||
@ -327,25 +329,27 @@ static void infrared_test_run_decoder(InfraredProtocol protocol, uint32_t test_i
|
||||
InfraredMessage* messages;
|
||||
uint32_t messages_count;
|
||||
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
|
||||
mu_assert(
|
||||
infrared_test_prepare_file(infrared_get_protocol_name(protocol)),
|
||||
"Failed to prepare test file");
|
||||
|
||||
string_printf(buf, "decoder_input%d", test_index);
|
||||
furi_string_printf(buf, "decoder_input%d", test_index);
|
||||
mu_assert(
|
||||
infrared_test_load_raw_signal(test->ff, string_get_cstr(buf), &timings, &timings_count),
|
||||
infrared_test_load_raw_signal(
|
||||
test->ff, furi_string_get_cstr(buf), &timings, &timings_count),
|
||||
"Failed to load raw signal from file");
|
||||
|
||||
string_printf(buf, "decoder_expected%d", test_index);
|
||||
furi_string_printf(buf, "decoder_expected%d", test_index);
|
||||
mu_assert(
|
||||
infrared_test_load_messages(test->ff, string_get_cstr(buf), &messages, &messages_count),
|
||||
infrared_test_load_messages(
|
||||
test->ff, furi_string_get_cstr(buf), &messages, &messages_count),
|
||||
"Failed to load messages from file");
|
||||
|
||||
flipper_format_buffered_file_close(test->ff);
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
|
||||
InfraredMessage message_decoded_check_local;
|
||||
bool level = 0;
|
||||
|
@ -53,14 +53,15 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {
|
||||
bool success = false;
|
||||
|
||||
FlipperFormat* file = flipper_format_file_alloc(nfc_test->storage);
|
||||
string_t file_type;
|
||||
string_init(file_type);
|
||||
FuriString* file_type;
|
||||
file_type = furi_string_alloc();
|
||||
uint32_t file_version = 0;
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(file, file_name)) break;
|
||||
if(!flipper_format_read_header(file, file_type, &file_version)) break;
|
||||
if(string_cmp_str(file_type, nfc_test_file_type) || file_version != nfc_test_file_version)
|
||||
if(furi_string_cmp_str(file_type, nfc_test_file_type) ||
|
||||
file_version != nfc_test_file_version)
|
||||
break;
|
||||
if(!flipper_format_read_uint32(file, "Data length", &nfc_test->test_data_len, 1)) break;
|
||||
if(nfc_test->test_data_len > NFC_TEST_DATA_MAX_LEN) break;
|
||||
@ -76,7 +77,7 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(file_type);
|
||||
furi_string_free(file_type);
|
||||
flipper_format_free(file);
|
||||
|
||||
return success;
|
||||
@ -174,8 +175,8 @@ MU_TEST(nfc_digital_signal_test) {
|
||||
MU_TEST(mf_classic_dict_test) {
|
||||
MfClassicDict* instance = NULL;
|
||||
uint64_t key = 0;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
instance = mf_classic_dict_alloc(MfClassicDictTypeUnitTest);
|
||||
mu_assert(instance != NULL, "mf_classic_dict_alloc\r\n");
|
||||
@ -184,7 +185,7 @@ MU_TEST(mf_classic_dict_test) {
|
||||
mf_classic_dict_get_total_keys(instance) == 0,
|
||||
"mf_classic_dict_get_total_keys == 0 assert failed\r\n");
|
||||
|
||||
string_set(temp_str, "2196FAD8115B");
|
||||
furi_string_set(temp_str, "2196FAD8115B");
|
||||
mu_assert(
|
||||
mf_classic_dict_add_key_str(instance, temp_str),
|
||||
"mf_classic_dict_add_key == true assert failed\r\n");
|
||||
@ -199,7 +200,7 @@ MU_TEST(mf_classic_dict_test) {
|
||||
mf_classic_dict_get_key_at_index_str(instance, temp_str, 0),
|
||||
"mf_classic_dict_get_key_at_index_str == true assert failed\r\n");
|
||||
mu_assert(
|
||||
string_cmp(temp_str, "2196FAD8115B") == 0,
|
||||
furi_string_cmp(temp_str, "2196FAD8115B") == 0,
|
||||
"string_cmp(temp_str, \"2196FAD8115B\") == 0 assert failed\r\n");
|
||||
|
||||
mu_assert(mf_classic_dict_rewind(instance), "mf_classic_dict_rewind == 1 assert failed\r\n");
|
||||
@ -216,7 +217,7 @@ MU_TEST(mf_classic_dict_test) {
|
||||
"mf_classic_dict_delete_index == true assert failed\r\n");
|
||||
|
||||
mf_classic_dict_free(instance);
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(nfc) {
|
||||
|
@ -75,7 +75,7 @@ typedef struct {
|
||||
bool visited;
|
||||
} StorageTestPath;
|
||||
|
||||
DICT_DEF2(StorageTestPathDict, string_t, STRING_OPLIST, StorageTestPath, M_POD_OPLIST)
|
||||
DICT_DEF2(StorageTestPathDict, FuriString*, FURI_STRING_OPLIST, StorageTestPath, M_POD_OPLIST)
|
||||
|
||||
static StorageTestPathDict_t*
|
||||
storage_test_paths_alloc(const StorageTestPathDesc paths[], size_t paths_count) {
|
||||
@ -83,15 +83,15 @@ static StorageTestPathDict_t*
|
||||
StorageTestPathDict_init(*data);
|
||||
|
||||
for(size_t i = 0; i < paths_count; i++) {
|
||||
string_t key;
|
||||
string_init_set(key, paths[i].path);
|
||||
FuriString* key;
|
||||
key = furi_string_alloc_set(paths[i].path);
|
||||
StorageTestPath value = {
|
||||
.is_dir = paths[i].is_dir,
|
||||
.visited = false,
|
||||
};
|
||||
|
||||
StorageTestPathDict_set_at(*data, key, value);
|
||||
string_clear(key);
|
||||
furi_string_free(key);
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -102,7 +102,7 @@ static void storage_test_paths_free(StorageTestPathDict_t* data) {
|
||||
free(data);
|
||||
}
|
||||
|
||||
static bool storage_test_paths_mark(StorageTestPathDict_t* data, string_t path, bool is_dir) {
|
||||
static bool storage_test_paths_mark(StorageTestPathDict_t* data, FuriString* path, bool is_dir) {
|
||||
bool found = false;
|
||||
|
||||
StorageTestPath* record = StorageTestPathDict_get(*data, path);
|
||||
@ -148,27 +148,27 @@ static bool write_file_13DA(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
static void storage_dirs_create(Storage* storage, const char* base) {
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
|
||||
storage_common_mkdir(storage, base);
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_paths); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_test_dirwalk_paths[i]);
|
||||
storage_common_mkdir(storage, string_get_cstr(path));
|
||||
furi_string_printf(path, "%s/%s", base, storage_test_dirwalk_paths[i]);
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(path));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_files); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_test_dirwalk_files[i]);
|
||||
write_file_13DA(storage, string_get_cstr(path));
|
||||
furi_string_printf(path, "%s/%s", base, storage_test_dirwalk_files[i]);
|
||||
write_file_13DA(storage, furi_string_get_cstr(path));
|
||||
}
|
||||
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
}
|
||||
|
||||
MU_TEST_1(test_dirwalk_full, Storage* storage) {
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
FileInfo fileinfo;
|
||||
|
||||
StorageTestPathDict_t* paths =
|
||||
@ -178,12 +178,12 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
|
||||
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
|
||||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
|
||||
mu_check(storage_test_paths_check(paths) == false);
|
||||
|
||||
@ -191,8 +191,8 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
|
||||
}
|
||||
|
||||
MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
FileInfo fileinfo;
|
||||
|
||||
StorageTestPathDict_t* paths = storage_test_paths_alloc(
|
||||
@ -203,12 +203,12 @@ MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
|
||||
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
|
||||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
|
||||
mu_check(storage_test_paths_check(paths) == false);
|
||||
|
||||
@ -230,8 +230,8 @@ static bool test_dirwalk_filter_no_folder_ext(const char* name, FileInfo* filein
|
||||
}
|
||||
|
||||
MU_TEST_1(test_dirwalk_filter, Storage* storage) {
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
FileInfo fileinfo;
|
||||
|
||||
StorageTestPathDict_t* paths = storage_test_paths_alloc(
|
||||
@ -242,12 +242,12 @@ MU_TEST_1(test_dirwalk_filter, Storage* storage) {
|
||||
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
|
||||
|
||||
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
|
||||
string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
|
||||
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
|
||||
}
|
||||
|
||||
dir_walk_free(dir_walk);
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
|
||||
mu_check(storage_test_paths_check(paths) == false);
|
||||
|
||||
|
@ -211,22 +211,22 @@ static bool check_file_13DA(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
static void storage_dir_create(Storage* storage, const char* base) {
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
|
||||
storage_common_mkdir(storage, base);
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
|
||||
storage_common_mkdir(storage, string_get_cstr(path));
|
||||
furi_string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(path));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
|
||||
write_file_13DA(storage, string_get_cstr(path));
|
||||
furi_string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
|
||||
write_file_13DA(storage, furi_string_get_cstr(path));
|
||||
}
|
||||
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
}
|
||||
|
||||
static void storage_dir_remove(Storage* storage, const char* base) {
|
||||
@ -235,15 +235,15 @@ static void storage_dir_remove(Storage* storage, const char* base) {
|
||||
|
||||
static bool storage_dir_rename_check(Storage* storage, const char* base) {
|
||||
bool result = false;
|
||||
string_t path;
|
||||
string_init(path);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc();
|
||||
|
||||
result = (storage_common_stat(storage, base, NULL) == FSE_OK);
|
||||
|
||||
if(result) {
|
||||
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
|
||||
result = (storage_common_stat(storage, string_get_cstr(path), NULL) == FSE_OK);
|
||||
furi_string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
|
||||
result = (storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK);
|
||||
if(!result) {
|
||||
break;
|
||||
}
|
||||
@ -252,15 +252,15 @@ static bool storage_dir_rename_check(Storage* storage, const char* base) {
|
||||
|
||||
if(result) {
|
||||
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
|
||||
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
|
||||
result = check_file_13DA(storage, string_get_cstr(path));
|
||||
furi_string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
|
||||
result = check_file_13DA(storage, furi_string_get_cstr(path));
|
||||
if(!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ static const char* stream_test_right_data =
|
||||
MU_TEST_1(stream_composite_subtest, Stream* stream) {
|
||||
const size_t data_size = 128;
|
||||
uint8_t data[data_size];
|
||||
string_t string_lee;
|
||||
string_init_set(string_lee, "lee");
|
||||
FuriString* string_lee;
|
||||
string_lee = furi_string_alloc_set("lee");
|
||||
|
||||
// test that stream is empty
|
||||
// "" -> ""
|
||||
@ -267,7 +267,7 @@ MU_TEST_1(stream_composite_subtest, Stream* stream) {
|
||||
mu_assert_int_eq(9, stream_tell(stream));
|
||||
mu_check(stream_eof(stream));
|
||||
|
||||
string_clear(string_lee);
|
||||
furi_string_free(string_lee);
|
||||
}
|
||||
|
||||
MU_TEST(stream_composite_test) {
|
||||
@ -416,10 +416,10 @@ MU_TEST(stream_buffered_write_after_read_test) {
|
||||
}
|
||||
|
||||
MU_TEST(stream_buffered_large_file_test) {
|
||||
string_t input_data;
|
||||
string_t output_data;
|
||||
string_init(input_data);
|
||||
string_init(output_data);
|
||||
FuriString* input_data;
|
||||
FuriString* output_data;
|
||||
input_data = furi_string_alloc();
|
||||
output_data = furi_string_alloc();
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@ -429,7 +429,7 @@ MU_TEST(stream_buffered_large_file_test) {
|
||||
const size_t rep_count = data_size / line_size + 1;
|
||||
|
||||
for(size_t i = 0; i < rep_count; ++i) {
|
||||
string_cat_printf(input_data, "%s\n", stream_test_data);
|
||||
furi_string_cat_printf(input_data, "%s\n", stream_test_data);
|
||||
}
|
||||
|
||||
// write test data to file
|
||||
@ -437,8 +437,8 @@ MU_TEST(stream_buffered_large_file_test) {
|
||||
mu_check(buffered_file_stream_open(
|
||||
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_assert_int_eq(0, stream_size(stream));
|
||||
mu_assert_int_eq(string_size(input_data), stream_write_string(stream, input_data));
|
||||
mu_assert_int_eq(string_size(input_data), stream_size(stream));
|
||||
mu_assert_int_eq(furi_string_size(input_data), stream_write_string(stream, input_data));
|
||||
mu_assert_int_eq(furi_string_size(input_data), stream_size(stream));
|
||||
|
||||
const size_t substr_start = 8;
|
||||
const size_t substr_len = 11;
|
||||
@ -475,23 +475,23 @@ MU_TEST(stream_buffered_large_file_test) {
|
||||
|
||||
// read the whole file
|
||||
mu_check(stream_rewind(stream));
|
||||
string_t tmp;
|
||||
string_init(tmp);
|
||||
FuriString* tmp;
|
||||
tmp = furi_string_alloc();
|
||||
while(stream_read_line(stream, tmp)) {
|
||||
string_cat(output_data, tmp);
|
||||
furi_string_cat(output_data, tmp);
|
||||
}
|
||||
string_clear(tmp);
|
||||
furi_string_free(tmp);
|
||||
|
||||
// check against generated data
|
||||
mu_assert_int_eq(string_size(input_data), string_size(output_data));
|
||||
mu_check(string_equal_p(input_data, output_data));
|
||||
mu_assert_int_eq(furi_string_size(input_data), furi_string_size(output_data));
|
||||
mu_check(furi_string_equal(input_data, output_data));
|
||||
mu_check(stream_eof(stream));
|
||||
|
||||
stream_free(stream);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
string_clear(input_data);
|
||||
string_clear(output_data);
|
||||
furi_string_free(input_data);
|
||||
furi_string_free(output_data);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(stream_suite) {
|
||||
|
@ -28,12 +28,12 @@ static void subghz_test_rx_callback(
|
||||
void* context) {
|
||||
UNUSED(receiver);
|
||||
UNUSED(context);
|
||||
string_t text;
|
||||
string_init(text);
|
||||
FuriString* text;
|
||||
text = furi_string_alloc();
|
||||
subghz_protocol_decoder_base_get_string(decoder_base, text);
|
||||
subghz_receiver_reset(receiver_handler);
|
||||
FURI_LOG_T(TAG, "\r\n%s", string_get_cstr(text));
|
||||
string_clear(text);
|
||||
FURI_LOG_T(TAG, "\r\n%s", furi_string_get_cstr(text));
|
||||
furi_string_free(text);
|
||||
subghz_test_decoder_count++;
|
||||
}
|
||||
|
||||
@ -141,8 +141,8 @@ static bool subghz_decode_random_test(const char* path) {
|
||||
static bool subghz_encoder_test(const char* path) {
|
||||
subghz_test_decoder_count = 0;
|
||||
uint32_t test_start = furi_get_tick();
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
bool file_load = false;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
@ -167,11 +167,11 @@ static bool subghz_encoder_test(const char* path) {
|
||||
} while(false);
|
||||
if(file_load) {
|
||||
SubGhzTransmitter* transmitter =
|
||||
subghz_transmitter_alloc_init(environment_handler, string_get_cstr(temp_str));
|
||||
subghz_transmitter_alloc_init(environment_handler, furi_string_get_cstr(temp_str));
|
||||
subghz_transmitter_deserialize(transmitter, fff_data_file);
|
||||
|
||||
SubGhzProtocolDecoderBase* decoder = subghz_receiver_search_decoder_base_by_name(
|
||||
receiver_handler, string_get_cstr(temp_str));
|
||||
receiver_handler, furi_string_get_cstr(temp_str));
|
||||
|
||||
if(decoder) {
|
||||
LevelDuration level_duration;
|
||||
@ -192,10 +192,11 @@ static bool subghz_encoder_test(const char* path) {
|
||||
flipper_format_free(fff_data_file);
|
||||
FURI_LOG_T(TAG, "\r\n Decoder count parse \033[0;33m%d\033[0m ", subghz_test_decoder_count);
|
||||
if(furi_get_tick() - test_start > TEST_TIMEOUT) {
|
||||
printf("\033[0;31mTest encoder %s ERROR TimeOut\033[0m\r\n", string_get_cstr(temp_str));
|
||||
printf(
|
||||
"\033[0;31mTest encoder %s ERROR TimeOut\033[0m\r\n", furi_string_get_cstr(temp_str));
|
||||
subghz_test_decoder_count = 0;
|
||||
}
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
|
||||
return subghz_test_decoder_count ? true : false;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include "m-string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
@ -11,6 +9,7 @@
|
||||
#define TAG "UnitTests"
|
||||
|
||||
int run_minunit_test_furi();
|
||||
int run_minunit_test_furi_string();
|
||||
int run_minunit_test_infrared();
|
||||
int run_minunit_test_rpc();
|
||||
int run_minunit_test_flipper_format();
|
||||
@ -33,6 +32,7 @@ typedef struct {
|
||||
|
||||
const UnitTest unit_tests[] = {
|
||||
{.name = "furi", .entry = run_minunit_test_furi},
|
||||
{.name = "furi_string", .entry = run_minunit_test_furi_string},
|
||||
{.name = "storage", .entry = run_minunit_test_storage},
|
||||
{.name = "stream", .entry = run_minunit_test_stream},
|
||||
{.name = "dirwalk", .entry = run_minunit_test_dirwalk},
|
||||
@ -63,7 +63,7 @@ void minunit_print_fail(const char* str) {
|
||||
printf(FURI_LOG_CLR_E "%s\r\n" FURI_LOG_CLR_RESET, str);
|
||||
}
|
||||
|
||||
void unit_tests_cli(Cli* cli, string_t args, void* context) {
|
||||
void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
UNUSED(args);
|
||||
UNUSED(context);
|
||||
@ -91,8 +91,8 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_size(args)) {
|
||||
if(string_cmp_str(args, unit_tests[i].name) == 0) {
|
||||
if(furi_string_size(args)) {
|
||||
if(furi_string_cmp_str(args, unit_tests[i].name) == 0) {
|
||||
failed_tests += unit_tests[i].entry();
|
||||
} else {
|
||||
printf("Skipping %s\r\n", unit_tests[i].name);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "archive_i.h"
|
||||
#include "m-string.h"
|
||||
|
||||
bool archive_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
@ -18,7 +17,7 @@ ArchiveApp* archive_alloc() {
|
||||
|
||||
archive->gui = furi_record_open(RECORD_GUI);
|
||||
archive->text_input = text_input_alloc();
|
||||
string_init(archive->fav_move_str);
|
||||
archive->fav_move_str = furi_string_alloc();
|
||||
|
||||
archive->view_dispatcher = view_dispatcher_alloc();
|
||||
archive->scene_manager = scene_manager_alloc(&archive_scene_handlers, archive);
|
||||
@ -58,7 +57,7 @@ void archive_free(ArchiveApp* archive) {
|
||||
view_dispatcher_free(archive->view_dispatcher);
|
||||
scene_manager_free(archive->scene_manager);
|
||||
browser_free(archive->browser);
|
||||
string_clear(archive->fav_move_str);
|
||||
furi_string_free(archive->fav_move_str);
|
||||
|
||||
text_input_free(archive->text_input);
|
||||
|
||||
|
@ -28,7 +28,7 @@ struct ArchiveApp {
|
||||
TextInput* text_input;
|
||||
Widget* widget;
|
||||
FuriPubSubSubscription* loader_stop_subscription;
|
||||
string_t fav_move_str;
|
||||
FuriString* fav_move_str;
|
||||
char text_store[MAX_NAME_LEN];
|
||||
char file_extension[MAX_EXT_LEN + 1];
|
||||
};
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "gui/modules/file_browser_worker.h"
|
||||
#include "m-string.h"
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
@ -19,7 +18,7 @@ static void
|
||||
|
||||
if((item_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser)) {
|
||||
archive_switch_tab(browser, browser->last_tab_switch_dir);
|
||||
} else if(!string_start_with_str_p(browser->path, "/app:")) {
|
||||
} else if(!furi_string_start_with_str(browser->path, "/app:")) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_reset(model->files);
|
||||
@ -51,12 +50,13 @@ static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
|
||||
});
|
||||
}
|
||||
|
||||
static void archive_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last) {
|
||||
static void
|
||||
archive_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
|
||||
furi_assert(context);
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
if(!is_last) {
|
||||
archive_add_file_item(browser, is_folder, string_get_cstr(item_path));
|
||||
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
@ -79,7 +79,7 @@ static void archive_long_load_cb(void* context) {
|
||||
|
||||
static void archive_file_browser_set_path(
|
||||
ArchiveBrowserView* browser,
|
||||
string_t path,
|
||||
FuriString* path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets) {
|
||||
furi_assert(browser);
|
||||
@ -133,7 +133,7 @@ void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
furi_assert(browser);
|
||||
furi_assert(target);
|
||||
|
||||
archive_get_items(browser, string_get_cstr(browser->path));
|
||||
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
||||
|
||||
if(!archive_file_get_array_size(browser) && archive_is_home(browser)) {
|
||||
archive_switch_tab(browser, TAB_RIGHT);
|
||||
@ -143,7 +143,7 @@ void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
uint16_t idx = 0;
|
||||
while(idx < files_array_size(model->files)) {
|
||||
ArchiveFile_t* current = files_array_get(model->files, idx);
|
||||
if(!string_search(current->path, target)) {
|
||||
if(!furi_string_search(current->path, target)) {
|
||||
model->item_idx = idx + model->array_offset;
|
||||
break;
|
||||
}
|
||||
@ -315,12 +315,12 @@ bool archive_is_home(ArchiveBrowserView* browser) {
|
||||
}
|
||||
|
||||
const char* default_path = archive_get_default_path(archive_get_tab(browser));
|
||||
return (string_cmp_str(browser->path, default_path) == 0);
|
||||
return (furi_string_cmp_str(browser->path, default_path) == 0);
|
||||
}
|
||||
|
||||
const char* archive_get_name(ArchiveBrowserView* browser) {
|
||||
ArchiveFile_t* selected = archive_get_current_file(browser);
|
||||
return string_get_cstr(selected->path);
|
||||
return furi_string_get_cstr(selected->path);
|
||||
}
|
||||
|
||||
void archive_set_tab(ArchiveBrowserView* browser, ArchiveTabEnum tab) {
|
||||
@ -339,7 +339,7 @@ void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
|
||||
ArchiveFile_t item;
|
||||
ArchiveFile_t_init(&item);
|
||||
string_set_str(item.path, name);
|
||||
furi_string_set(item.path, name);
|
||||
archive_set_file_type(&item, name, false, true);
|
||||
|
||||
with_view_model(
|
||||
@ -358,8 +358,8 @@ void archive_add_file_item(ArchiveBrowserView* browser, bool is_folder, const ch
|
||||
ArchiveFile_t item;
|
||||
|
||||
ArchiveFile_t_init(&item);
|
||||
string_init_set_str(item.path, name);
|
||||
archive_set_file_type(&item, string_get_cstr(browser->path), is_folder, false);
|
||||
item.path = furi_string_alloc_set(name);
|
||||
archive_set_file_type(&item, furi_string_get_cstr(browser->path), is_folder, false);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
@ -379,7 +379,8 @@ void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {
|
||||
model->menu_idx = 0;
|
||||
ArchiveFile_t* selected =
|
||||
files_array_get(model->files, model->item_idx - model->array_offset);
|
||||
selected->fav = archive_is_favorite("%s", string_get_cstr(selected->path));
|
||||
selected->fav =
|
||||
archive_is_favorite("%s", furi_string_get_cstr(selected->path));
|
||||
}
|
||||
} else {
|
||||
model->menu = false;
|
||||
@ -400,14 +401,14 @@ void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
|
||||
});
|
||||
}
|
||||
|
||||
static bool archive_is_dir_exists(string_t path) {
|
||||
if(string_equal_str_p(path, STORAGE_ANY_PATH_PREFIX)) {
|
||||
static bool archive_is_dir_exists(FuriString* path) {
|
||||
if(furi_string_equal(path, STORAGE_ANY_PATH_PREFIX)) {
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
state = true;
|
||||
}
|
||||
@ -431,16 +432,16 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
||||
browser->is_root = true;
|
||||
archive_set_tab(browser, tab);
|
||||
|
||||
string_set_str(browser->path, archive_get_default_path(tab));
|
||||
furi_string_set(browser->path, archive_get_default_path(tab));
|
||||
bool tab_empty = true;
|
||||
if(tab == ArchiveTabFavorites) {
|
||||
if(archive_favorites_count(browser) > 0) {
|
||||
tab_empty = false;
|
||||
}
|
||||
} else if(string_start_with_str_p(browser->path, "/app:")) {
|
||||
char* app_name = strchr(string_get_cstr(browser->path), ':');
|
||||
} else if(furi_string_start_with_str(browser->path, "/app:")) {
|
||||
char* app_name = strchr(furi_string_get_cstr(browser->path), ':');
|
||||
if(app_name != NULL) {
|
||||
if(archive_app_is_available(browser, string_get_cstr(browser->path))) {
|
||||
if(archive_app_is_available(browser, furi_string_get_cstr(browser->path))) {
|
||||
tab_empty = false;
|
||||
}
|
||||
}
|
||||
@ -463,12 +464,12 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
||||
model->array_offset = 0;
|
||||
return false;
|
||||
});
|
||||
archive_get_items(browser, string_get_cstr(browser->path));
|
||||
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
}
|
||||
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, string_t path) {
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, FuriString* path) {
|
||||
furi_assert(browser);
|
||||
furi_assert(path);
|
||||
|
||||
@ -480,7 +481,7 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t path) {
|
||||
return false;
|
||||
});
|
||||
|
||||
string_set(browser->path, path);
|
||||
furi_string_set(browser->path, path);
|
||||
file_browser_worker_folder_enter(browser->worker, path, idx_temp);
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,6 @@ void archive_show_file_menu(ArchiveBrowserView* browser, bool show);
|
||||
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active);
|
||||
|
||||
void archive_switch_tab(ArchiveBrowserView* browser, InputKey key);
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, string_t name);
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, FuriString* name);
|
||||
void archive_leave_dir(ArchiveBrowserView* browser);
|
||||
void archive_refresh_dir(ArchiveBrowserView* browser);
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#define ARCHIVE_FAV_FILE_BUF_LEN 32
|
||||
|
||||
static bool archive_favorites_read_line(File* file, string_t str_result) {
|
||||
string_reset(str_result);
|
||||
static bool archive_favorites_read_line(File* file, FuriString* str_result) {
|
||||
furi_string_reset(str_result);
|
||||
uint8_t buffer[ARCHIVE_FAV_FILE_BUF_LEN];
|
||||
bool result = false;
|
||||
|
||||
@ -34,7 +34,7 @@ static bool archive_favorites_read_line(File* file, string_t str_result) {
|
||||
result = true;
|
||||
break;
|
||||
} else {
|
||||
string_push_back(str_result, buffer[i]);
|
||||
furi_string_push_back(str_result, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,8 +52,8 @@ uint16_t archive_favorites_count(void* context) {
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
FuriString* buffer;
|
||||
buffer = furi_string_alloc();
|
||||
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
uint16_t lines = 0;
|
||||
@ -63,7 +63,7 @@ uint16_t archive_favorites_count(void* context) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue; // Skip empty lines
|
||||
}
|
||||
++lines;
|
||||
@ -72,7 +72,7 @@ uint16_t archive_favorites_count(void* context) {
|
||||
|
||||
storage_file_close(file);
|
||||
|
||||
string_clear(buffer);
|
||||
furi_string_free(buffer);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
@ -80,8 +80,8 @@ uint16_t archive_favorites_count(void* context) {
|
||||
}
|
||||
|
||||
static bool archive_favourites_rescan() {
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
FuriString* buffer;
|
||||
buffer = furi_string_alloc();
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
@ -91,23 +91,25 @@ static bool archive_favourites_rescan() {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(NULL, string_get_cstr(buffer))) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
if(furi_string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(NULL, furi_string_get_cstr(buffer))) {
|
||||
archive_file_append(
|
||||
ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
||||
}
|
||||
} else {
|
||||
if(storage_file_exists(storage, string_get_cstr(buffer))) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
|
||||
archive_file_append(
|
||||
ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
furi_string_free(buffer);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(storage, ARCHIVE_FAV_PATH);
|
||||
@ -127,9 +129,9 @@ bool archive_favorites_read(void* context) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
string_t buffer;
|
||||
FuriString* buffer;
|
||||
FileInfo file_info;
|
||||
string_init(buffer);
|
||||
buffer = furi_string_alloc();
|
||||
|
||||
bool need_refresh = false;
|
||||
uint16_t file_count = 0;
|
||||
@ -143,33 +145,33 @@ bool archive_favorites_read(void* context) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(browser, string_get_cstr(buffer))) {
|
||||
archive_add_app_item(browser, string_get_cstr(buffer));
|
||||
if(furi_string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(browser, furi_string_get_cstr(buffer))) {
|
||||
archive_add_app_item(browser, furi_string_get_cstr(buffer));
|
||||
file_count++;
|
||||
} else {
|
||||
need_refresh = true;
|
||||
}
|
||||
} else {
|
||||
if(storage_file_exists(storage, string_get_cstr(buffer))) {
|
||||
storage_common_stat(storage, string_get_cstr(buffer), &file_info);
|
||||
if(storage_file_exists(storage, furi_string_get_cstr(buffer))) {
|
||||
storage_common_stat(storage, furi_string_get_cstr(buffer), &file_info);
|
||||
archive_add_file_item(
|
||||
browser, (file_info.flags & FSF_DIRECTORY), string_get_cstr(buffer));
|
||||
browser, (file_info.flags & FSF_DIRECTORY), furi_string_get_cstr(buffer));
|
||||
file_count++;
|
||||
} else {
|
||||
need_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
string_reset(buffer);
|
||||
furi_string_reset(buffer);
|
||||
}
|
||||
}
|
||||
storage_file_close(file);
|
||||
string_clear(buffer);
|
||||
furi_string_free(buffer);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
@ -183,14 +185,14 @@ bool archive_favorites_read(void* context) {
|
||||
}
|
||||
|
||||
bool archive_favorites_delete(const char* format, ...) {
|
||||
string_t buffer;
|
||||
string_t filename;
|
||||
FuriString* buffer;
|
||||
FuriString* filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
filename = furi_string_alloc_vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
string_init(buffer);
|
||||
buffer = furi_string_alloc();
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
@ -201,18 +203,18 @@ bool archive_favorites_delete(const char* format, ...) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, filename)) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
if(furi_string_search(buffer, filename)) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
string_clear(filename);
|
||||
furi_string_free(buffer);
|
||||
furi_string_free(filename);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
@ -226,14 +228,14 @@ bool archive_favorites_delete(const char* format, ...) {
|
||||
}
|
||||
|
||||
bool archive_is_favorite(const char* format, ...) {
|
||||
string_t buffer;
|
||||
string_t filename;
|
||||
FuriString* buffer;
|
||||
FuriString* filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
filename = furi_string_alloc_vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
string_init(buffer);
|
||||
buffer = furi_string_alloc();
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
@ -245,10 +247,10 @@ bool archive_is_favorite(const char* format, ...) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
if(!string_search(buffer, filename)) {
|
||||
if(!furi_string_search(buffer, filename)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -256,8 +258,8 @@ bool archive_is_favorite(const char* format, ...) {
|
||||
}
|
||||
|
||||
storage_file_close(file);
|
||||
string_clear(buffer);
|
||||
string_clear(filename);
|
||||
furi_string_free(buffer);
|
||||
furi_string_free(filename);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
@ -271,13 +273,13 @@ bool archive_favorites_rename(const char* src, const char* dst) {
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
string_t path;
|
||||
string_t buffer;
|
||||
FuriString* path;
|
||||
FuriString* buffer;
|
||||
|
||||
string_init(buffer);
|
||||
string_init(path);
|
||||
buffer = furi_string_alloc();
|
||||
path = furi_string_alloc();
|
||||
|
||||
string_printf(path, "%s", src);
|
||||
furi_string_printf(path, "%s", src);
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
@ -285,19 +287,19 @@ bool archive_favorites_rename(const char* src, const char* dst) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
if(!furi_string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
archive_file_append(
|
||||
ARCHIVE_FAV_TEMP_PATH,
|
||||
"%s\n",
|
||||
string_search(buffer, path) ? string_get_cstr(buffer) : dst);
|
||||
furi_string_search(buffer, path) ? furi_string_get_cstr(buffer) : dst);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
string_clear(path);
|
||||
furi_string_free(buffer);
|
||||
furi_string_free(path);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
@ -325,7 +327,7 @@ void archive_favorites_save(void* context) {
|
||||
|
||||
for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
|
||||
ArchiveFile_t* item = archive_get_file_at(browser, i);
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(item->path));
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", furi_string_get_cstr(item->path));
|
||||
}
|
||||
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
|
@ -15,10 +15,10 @@ void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder
|
||||
} else {
|
||||
for(size_t i = 0; i < COUNT_OF(known_ext); i++) {
|
||||
if((known_ext[i][0] == '?') || (known_ext[i][0] == '*')) continue;
|
||||
if(string_search_str(file->path, known_ext[i], 0) != STRING_FAILURE) {
|
||||
if(furi_string_search(file->path, known_ext[i], 0) != FURI_STRING_FAILURE) {
|
||||
if(i == ArchiveFileTypeBadUsb) {
|
||||
if(string_search_str(file->path, archive_get_default_path(ArchiveTabBadUsb)) ==
|
||||
0) {
|
||||
if(furi_string_search(
|
||||
file->path, archive_get_default_path(ArchiveTabBadUsb)) == 0) {
|
||||
file->type = i;
|
||||
return; // *.txt file is a BadUSB script only if it is in BadUSB folder
|
||||
}
|
||||
@ -54,10 +54,10 @@ bool archive_get_items(void* context, const char* path) {
|
||||
void archive_file_append(const char* path, const char* format, ...) {
|
||||
furi_assert(path);
|
||||
|
||||
string_t string;
|
||||
FuriString* string;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(string, format, args);
|
||||
string = furi_string_alloc_vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
@ -66,7 +66,7 @@ void archive_file_append(const char* path, const char* format, ...) {
|
||||
bool res = storage_file_open(file, path, FSAM_WRITE, FSOM_OPEN_APPEND);
|
||||
|
||||
if(res) {
|
||||
storage_file_write(file, string_get_cstr(string), string_size(string));
|
||||
storage_file_write(file, furi_string_get_cstr(string), furi_string_size(string));
|
||||
}
|
||||
|
||||
storage_file_close(file);
|
||||
@ -77,35 +77,35 @@ void archive_file_append(const char* path, const char* format, ...) {
|
||||
void archive_delete_file(void* context, const char* format, ...) {
|
||||
furi_assert(context);
|
||||
|
||||
string_t filename;
|
||||
FuriString* filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
filename = furi_string_alloc_vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
ArchiveBrowserView* browser = context;
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FileInfo fileinfo;
|
||||
storage_common_stat(fs_api, string_get_cstr(filename), &fileinfo);
|
||||
storage_common_stat(fs_api, furi_string_get_cstr(filename), &fileinfo);
|
||||
|
||||
bool res = false;
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
res = storage_simply_remove_recursive(fs_api, string_get_cstr(filename));
|
||||
res = storage_simply_remove_recursive(fs_api, furi_string_get_cstr(filename));
|
||||
} else {
|
||||
res = (storage_common_remove(fs_api, string_get_cstr(filename)) == FSE_OK);
|
||||
res = (storage_common_remove(fs_api, furi_string_get_cstr(filename)) == FSE_OK);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(archive_is_favorite("%s", string_get_cstr(filename))) {
|
||||
archive_favorites_delete("%s", string_get_cstr(filename));
|
||||
if(archive_is_favorite("%s", furi_string_get_cstr(filename))) {
|
||||
archive_favorites_delete("%s", furi_string_get_cstr(filename));
|
||||
}
|
||||
|
||||
if(res) {
|
||||
archive_file_array_rm_selected(browser);
|
||||
}
|
||||
|
||||
string_clear(filename);
|
||||
furi_string_free(filename);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-array.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
typedef enum {
|
||||
@ -19,7 +19,7 @@ typedef enum {
|
||||
} ArchiveFileTypeEnum;
|
||||
|
||||
typedef struct {
|
||||
string_t path;
|
||||
FuriString* path;
|
||||
ArchiveFileTypeEnum type;
|
||||
bool fav;
|
||||
bool is_app;
|
||||
@ -29,25 +29,25 @@ static void ArchiveFile_t_init(ArchiveFile_t* obj) {
|
||||
obj->type = ArchiveFileTypeUnknown;
|
||||
obj->is_app = false;
|
||||
obj->fav = false;
|
||||
string_init(obj->path);
|
||||
obj->path = furi_string_alloc();
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_init_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
obj->type = src->type;
|
||||
obj->is_app = src->is_app;
|
||||
obj->fav = src->fav;
|
||||
string_init_set(obj->path, src->path);
|
||||
obj->path = furi_string_alloc_set(src->path);
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
obj->type = src->type;
|
||||
obj->is_app = src->is_app;
|
||||
obj->fav = src->fav;
|
||||
string_set(obj->path, src->path);
|
||||
furi_string_set(obj->path, src->path);
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
|
||||
string_clear(obj->path);
|
||||
furi_string_free(obj->path);
|
||||
}
|
||||
|
||||
ARRAY_DEF(
|
||||
|
@ -40,14 +40,14 @@ static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selec
|
||||
|
||||
LoaderStatus status;
|
||||
if(selected->is_app) {
|
||||
char* param = strrchr(string_get_cstr(selected->path), '/');
|
||||
char* param = strrchr(furi_string_get_cstr(selected->path), '/');
|
||||
if(param != NULL) {
|
||||
param++;
|
||||
}
|
||||
status = loader_start(loader, flipper_app_name[selected->type], param);
|
||||
} else {
|
||||
status = loader_start(
|
||||
loader, flipper_app_name[selected->type], string_get_cstr(selected->path));
|
||||
loader, flipper_app_name[selected->type], furi_string_get_cstr(selected->path));
|
||||
}
|
||||
|
||||
if(status != LoaderStatusOk) {
|
||||
@ -159,13 +159,13 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventEnterFavMove:
|
||||
string_set(archive->fav_move_str, selected->path);
|
||||
furi_string_set(archive->fav_move_str, selected->path);
|
||||
archive_show_file_menu(browser, false);
|
||||
archive_favorites_move_mode(archive->browser, true);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventExitFavMove:
|
||||
archive_update_focus(browser, string_get_cstr(archive->fav_move_str));
|
||||
archive_update_focus(browser, furi_string_get_cstr(archive->fav_move_str));
|
||||
archive_favorites_move_mode(archive->browser, false);
|
||||
consumed = true;
|
||||
break;
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "../helpers/archive_apps.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "toolbox/path.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#define SCENE_DELETE_CUSTOM_EVENT (0UL)
|
||||
#define MAX_TEXT_INPUT_LEN 22
|
||||
@ -26,18 +25,18 @@ void archive_scene_delete_on_enter(void* context) {
|
||||
widget_add_button_element(
|
||||
app->widget, GuiButtonTypeRight, "Delete", archive_scene_delete_widget_callback, app);
|
||||
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
|
||||
ArchiveFile_t* current = archive_get_current_file(app->browser);
|
||||
path_extract_filename(current->path, filename, false);
|
||||
|
||||
char delete_str[64];
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", string_get_cstr(filename));
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", furi_string_get_cstr(filename));
|
||||
widget_add_text_box_element(
|
||||
app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);
|
||||
|
||||
string_clear(filename);
|
||||
furi_string_free(filename);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ArchiveViewWidget);
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ void archive_scene_rename_on_enter(void* context) {
|
||||
TextInput* text_input = archive->text_input;
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
||||
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
path_extract_filename(current->path, filename, true);
|
||||
strlcpy(archive->text_store, string_get_cstr(filename), MAX_NAME_LEN);
|
||||
strlcpy(archive->text_store, furi_string_get_cstr(filename), MAX_NAME_LEN);
|
||||
|
||||
path_extract_extension(current->path, archive->file_extension, MAX_EXT_LEN);
|
||||
|
||||
@ -37,10 +37,10 @@ void archive_scene_rename_on_enter(void* context) {
|
||||
false);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
string_get_cstr(archive->browser->path), archive->file_extension, "");
|
||||
furi_string_get_cstr(archive->browser->path), archive->file_extension, "");
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
string_clear(filename);
|
||||
furi_string_free(filename);
|
||||
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
|
||||
}
|
||||
@ -56,19 +56,19 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
const char* path_src = archive_get_name(archive->browser);
|
||||
ArchiveFile_t* file = archive_get_current_file(archive->browser);
|
||||
|
||||
string_t path_dst;
|
||||
string_init(path_dst);
|
||||
FuriString* path_dst;
|
||||
path_dst = furi_string_alloc();
|
||||
path_extract_dirname(path_src, path_dst);
|
||||
string_cat_printf(path_dst, "/%s%s", archive->text_store, known_ext[file->type]);
|
||||
furi_string_cat_printf(path_dst, "/%s%s", archive->text_store, known_ext[file->type]);
|
||||
|
||||
storage_common_rename(fs_api, path_src, string_get_cstr(path_dst));
|
||||
storage_common_rename(fs_api, path_src, furi_string_get_cstr(path_dst));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(file->fav) {
|
||||
archive_favorites_rename(path_src, string_get_cstr(path_dst));
|
||||
archive_favorites_rename(path_src, furi_string_get_cstr(path_dst));
|
||||
}
|
||||
|
||||
string_clear(path_dst);
|
||||
furi_string_free(path_dst);
|
||||
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneBrowser);
|
||||
consumed = true;
|
||||
|
@ -47,35 +47,35 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
elements_slightly_rounded_frame(canvas, 70, 16, 58, 48);
|
||||
|
||||
string_t menu[MENU_ITEMS];
|
||||
FuriString* menu[MENU_ITEMS];
|
||||
|
||||
string_init_set_str(menu[0], "Run in app");
|
||||
string_init_set_str(menu[1], "Pin");
|
||||
string_init_set_str(menu[2], "Rename");
|
||||
string_init_set_str(menu[3], "Delete");
|
||||
menu[0] = furi_string_alloc_set("Run in app");
|
||||
menu[1] = furi_string_alloc_set("Pin");
|
||||
menu[2] = furi_string_alloc_set("Rename");
|
||||
menu[3] = furi_string_alloc_set("Delete");
|
||||
|
||||
ArchiveFile_t* selected = files_array_get(model->files, model->item_idx - model->array_offset);
|
||||
|
||||
if((selected->fav) || (model->tab_idx == ArchiveTabFavorites)) {
|
||||
string_set_str(menu[1], "Unpin");
|
||||
furi_string_set(menu[1], "Unpin");
|
||||
}
|
||||
|
||||
if(!archive_is_known_app(selected->type)) {
|
||||
string_set_str(menu[0], "---");
|
||||
string_set_str(menu[1], "---");
|
||||
string_set_str(menu[2], "---");
|
||||
furi_string_set(menu[0], "---");
|
||||
furi_string_set(menu[1], "---");
|
||||
furi_string_set(menu[2], "---");
|
||||
} else {
|
||||
if(model->tab_idx == ArchiveTabFavorites) {
|
||||
string_set_str(menu[2], "Move");
|
||||
string_set_str(menu[3], "---");
|
||||
furi_string_set(menu[2], "Move");
|
||||
furi_string_set(menu[3], "---");
|
||||
} else if(selected->is_app) {
|
||||
string_set_str(menu[2], "---");
|
||||
furi_string_set(menu[2], "---");
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < MENU_ITEMS; i++) {
|
||||
canvas_draw_str(canvas, 82, 27 + i * 11, string_get_cstr(menu[i]));
|
||||
string_clear(menu[i]);
|
||||
canvas_draw_str(canvas, 82, 27 + i * 11, furi_string_get_cstr(menu[i]));
|
||||
furi_string_free(menu[i]);
|
||||
}
|
||||
|
||||
canvas_draw_icon(canvas, 74, 20 + model->menu_idx * 11, &I_ButtonRight_4x7);
|
||||
@ -118,8 +118,8 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
bool scrollbar = model->item_cnt > 4;
|
||||
|
||||
for(uint32_t i = 0; i < MIN(model->item_cnt, MENU_ITEMS); ++i) {
|
||||
string_t str_buf;
|
||||
string_init(str_buf);
|
||||
FuriString* str_buf;
|
||||
str_buf = furi_string_alloc();
|
||||
int32_t idx = CLAMP((uint32_t)(i + model->list_offset), model->item_cnt, 0u);
|
||||
uint8_t x_offset = (model->move_fav && model->item_idx == idx) ? MOVE_OFFSET : 0;
|
||||
|
||||
@ -131,7 +131,7 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
path_extract_filename(file->path, str_buf, archive_is_known_app(file->type));
|
||||
file_type = file->type;
|
||||
} else {
|
||||
string_set_str(str_buf, "---");
|
||||
furi_string_set(str_buf, "---");
|
||||
}
|
||||
|
||||
elements_string_fit_width(
|
||||
@ -144,9 +144,10 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
}
|
||||
|
||||
canvas_draw_icon(canvas, 2 + x_offset, 16 + i * FRAME_HEIGHT, ArchiveItemIcons[file_type]);
|
||||
canvas_draw_str(canvas, 15 + x_offset, 24 + i * FRAME_HEIGHT, string_get_cstr(str_buf));
|
||||
canvas_draw_str(
|
||||
canvas, 15 + x_offset, 24 + i * FRAME_HEIGHT, furi_string_get_cstr(str_buf));
|
||||
|
||||
string_clear(str_buf);
|
||||
furi_string_free(str_buf);
|
||||
}
|
||||
|
||||
if(scrollbar) {
|
||||
@ -361,7 +362,7 @@ ArchiveBrowserView* browser_alloc() {
|
||||
view_set_draw_callback(browser->view, archive_view_render);
|
||||
view_set_input_callback(browser->view, archive_view_input);
|
||||
|
||||
string_init_set_str(browser->path, archive_get_default_path(TAB_DEFAULT));
|
||||
browser->path = furi_string_alloc_set(archive_get_default_path(TAB_DEFAULT));
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
@ -386,7 +387,7 @@ void browser_free(ArchiveBrowserView* browser) {
|
||||
return false;
|
||||
});
|
||||
|
||||
string_clear(browser->path);
|
||||
furi_string_free(browser->path);
|
||||
|
||||
view_free(browser->view);
|
||||
free(browser);
|
||||
|
@ -77,7 +77,7 @@ struct ArchiveBrowserView {
|
||||
bool worker_running;
|
||||
ArchiveBrowserViewCallback callback;
|
||||
void* context;
|
||||
string_t path;
|
||||
FuriString* path;
|
||||
InputKey last_tab_switch_dir;
|
||||
bool is_root;
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "bad_usb_app_i.h"
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
@ -26,10 +25,10 @@ static void bad_usb_app_tick_event_callback(void* context) {
|
||||
BadUsbApp* bad_usb_app_alloc(char* arg) {
|
||||
BadUsbApp* app = malloc(sizeof(BadUsbApp));
|
||||
|
||||
string_init(app->file_path);
|
||||
app->file_path = furi_string_alloc();
|
||||
|
||||
if(arg && strlen(arg)) {
|
||||
string_set_str(app->file_path, arg);
|
||||
furi_string_set(app->file_path, arg);
|
||||
}
|
||||
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
@ -64,10 +63,10 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {
|
||||
app->error = BadUsbAppErrorCloseRpc;
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
|
||||
} else {
|
||||
if(!string_empty_p(app->file_path)) {
|
||||
if(!furi_string_empty(app->file_path)) {
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneWork);
|
||||
} else {
|
||||
string_set_str(app->file_path, BAD_USB_APP_PATH_FOLDER);
|
||||
furi_string_set(app->file_path, BAD_USB_APP_PATH_FOLDER);
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
|
||||
}
|
||||
}
|
||||
@ -95,7 +94,7 @@ void bad_usb_app_free(BadUsbApp* app) {
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
|
||||
string_clear(app->file_path);
|
||||
furi_string_free(app->file_path);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct BadUsbApp {
|
||||
Widget* widget;
|
||||
|
||||
BadUsbAppError error;
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
BadUsb* bad_usb_view;
|
||||
BadUsbScript* bad_usb_script;
|
||||
};
|
||||
|
@ -26,16 +26,16 @@ typedef enum {
|
||||
struct BadUsbScript {
|
||||
FuriHalUsbHidConfig hid_cfg;
|
||||
BadUsbState st;
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
uint32_t defdelay;
|
||||
FuriThread* thread;
|
||||
uint8_t file_buf[FILE_BUFFER_LEN + 1];
|
||||
uint8_t buf_start;
|
||||
uint8_t buf_len;
|
||||
bool file_end;
|
||||
string_t line;
|
||||
FuriString* line;
|
||||
|
||||
string_t line_prev;
|
||||
FuriString* line_prev;
|
||||
uint32_t repeat_cnt;
|
||||
};
|
||||
|
||||
@ -230,9 +230,9 @@ static uint16_t ducky_get_keycode(const char* param, bool accept_chars) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t ducky_parse_line(BadUsbScript* bad_usb, string_t line) {
|
||||
uint32_t line_len = string_size(line);
|
||||
const char* line_tmp = string_get_cstr(line);
|
||||
static int32_t ducky_parse_line(BadUsbScript* bad_usb, FuriString* line) {
|
||||
uint32_t line_len = furi_string_size(line);
|
||||
const char* line_tmp = furi_string_get_cstr(line);
|
||||
bool state = false;
|
||||
|
||||
for(uint32_t i = 0; i < line_len; i++) {
|
||||
@ -337,7 +337,7 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
uint8_t ret = 0;
|
||||
uint32_t line_len = 0;
|
||||
|
||||
string_reset(bad_usb->line);
|
||||
furi_string_reset(bad_usb->line);
|
||||
|
||||
do {
|
||||
ret = storage_file_read(script_file, bad_usb->file_buf, FILE_BUFFER_LEN);
|
||||
@ -347,7 +347,7 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
line_len = 0;
|
||||
} else {
|
||||
if(bad_usb->st.line_nb == 0) { // Save first line
|
||||
string_push_back(bad_usb->line, bad_usb->file_buf[i]);
|
||||
furi_string_push_back(bad_usb->line, bad_usb->file_buf[i]);
|
||||
}
|
||||
line_len++;
|
||||
}
|
||||
@ -360,7 +360,7 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
}
|
||||
} while(ret > 0);
|
||||
|
||||
const char* line_tmp = string_get_cstr(bad_usb->line);
|
||||
const char* line_tmp = furi_string_get_cstr(bad_usb->line);
|
||||
bool id_set = false; // Looking for ID command at first line
|
||||
if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
|
||||
id_set = ducky_set_usb_id(bad_usb, &line_tmp[strlen(ducky_cmd_id) + 1]);
|
||||
@ -373,7 +373,7 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
}
|
||||
|
||||
storage_file_seek(script_file, 0, true);
|
||||
string_reset(bad_usb->line);
|
||||
furi_string_reset(bad_usb->line);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -395,8 +395,8 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil
|
||||
}
|
||||
}
|
||||
|
||||
string_set(bad_usb->line_prev, bad_usb->line);
|
||||
string_reset(bad_usb->line);
|
||||
furi_string_set(bad_usb->line_prev, bad_usb->line);
|
||||
furi_string_reset(bad_usb->line);
|
||||
|
||||
while(1) {
|
||||
if(bad_usb->buf_len == 0) {
|
||||
@ -413,7 +413,7 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil
|
||||
if(bad_usb->buf_len == 0) return SCRIPT_STATE_END;
|
||||
}
|
||||
for(uint8_t i = bad_usb->buf_start; i < (bad_usb->buf_start + bad_usb->buf_len); i++) {
|
||||
if(bad_usb->file_buf[i] == '\n' && string_size(bad_usb->line) > 0) {
|
||||
if(bad_usb->file_buf[i] == '\n' && furi_string_size(bad_usb->line) > 0) {
|
||||
bad_usb->st.line_cur++;
|
||||
bad_usb->buf_len = bad_usb->buf_len + bad_usb->buf_start - (i + 1);
|
||||
bad_usb->buf_start = i + 1;
|
||||
@ -426,7 +426,7 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil
|
||||
return (delay_val + bad_usb->defdelay);
|
||||
}
|
||||
} else {
|
||||
string_push_back(bad_usb->line, bad_usb->file_buf[i]);
|
||||
furi_string_push_back(bad_usb->line, bad_usb->file_buf[i]);
|
||||
}
|
||||
}
|
||||
bad_usb->buf_len = 0;
|
||||
@ -456,8 +456,8 @@ static int32_t bad_usb_worker(void* context) {
|
||||
|
||||
FURI_LOG_I(WORKER_TAG, "Init");
|
||||
File* script_file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
|
||||
string_init(bad_usb->line);
|
||||
string_init(bad_usb->line_prev);
|
||||
bad_usb->line = furi_string_alloc();
|
||||
bad_usb->line_prev = furi_string_alloc();
|
||||
|
||||
furi_hal_hid_set_state_callback(bad_usb_hid_state_callback, bad_usb);
|
||||
|
||||
@ -465,7 +465,7 @@ static int32_t bad_usb_worker(void* context) {
|
||||
if(worker_state == BadUsbStateInit) { // State: initialization
|
||||
if(storage_file_open(
|
||||
script_file,
|
||||
string_get_cstr(bad_usb->file_path),
|
||||
furi_string_get_cstr(bad_usb->file_path),
|
||||
FSAM_READ,
|
||||
FSOM_OPEN_EXISTING)) {
|
||||
if((ducky_script_preload(bad_usb, script_file)) && (bad_usb->st.line_nb > 0)) {
|
||||
@ -577,20 +577,20 @@ static int32_t bad_usb_worker(void* context) {
|
||||
|
||||
storage_file_close(script_file);
|
||||
storage_file_free(script_file);
|
||||
string_clear(bad_usb->line);
|
||||
string_clear(bad_usb->line_prev);
|
||||
furi_string_free(bad_usb->line);
|
||||
furi_string_free(bad_usb->line_prev);
|
||||
|
||||
FURI_LOG_I(WORKER_TAG, "End");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BadUsbScript* bad_usb_script_open(string_t file_path) {
|
||||
BadUsbScript* bad_usb_script_open(FuriString* file_path) {
|
||||
furi_assert(file_path);
|
||||
|
||||
BadUsbScript* bad_usb = malloc(sizeof(BadUsbScript));
|
||||
string_init(bad_usb->file_path);
|
||||
string_set(bad_usb->file_path, file_path);
|
||||
bad_usb->file_path = furi_string_alloc();
|
||||
furi_string_set(bad_usb->file_path, file_path);
|
||||
|
||||
bad_usb->st.state = BadUsbStateInit;
|
||||
|
||||
@ -609,7 +609,7 @@ void bad_usb_script_close(BadUsbScript* bad_usb) {
|
||||
furi_thread_flags_set(furi_thread_get_id(bad_usb->thread), WorkerEvtEnd);
|
||||
furi_thread_join(bad_usb->thread);
|
||||
furi_thread_free(bad_usb->thread);
|
||||
string_clear(bad_usb->file_path);
|
||||
furi_string_free(bad_usb->file_path);
|
||||
free(bad_usb);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-string.h>
|
||||
|
||||
typedef struct BadUsbScript BadUsbScript;
|
||||
|
||||
@ -28,7 +27,7 @@ typedef struct {
|
||||
uint16_t error_line;
|
||||
} BadUsbState;
|
||||
|
||||
BadUsbScript* bad_usb_script_open(string_t file_path);
|
||||
BadUsbScript* bad_usb_script_open(FuriString* file_path);
|
||||
|
||||
void bad_usb_script_close(BadUsbScript* bad_usb);
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "../bad_usb_app_i.h"
|
||||
#include "../views/bad_usb_view.h"
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
#include "toolbox/path.h"
|
||||
|
||||
void bad_usb_scene_work_ok_callback(InputType type, void* context) {
|
||||
@ -27,14 +26,14 @@ bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
|
||||
void bad_usb_scene_work_on_enter(void* context) {
|
||||
BadUsbApp* app = context;
|
||||
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
FuriString* file_name;
|
||||
file_name = furi_string_alloc();
|
||||
|
||||
path_extract_filename(app->file_path, file_name, true);
|
||||
bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
|
||||
bad_usb_set_file_name(app->bad_usb_view, furi_string_get_cstr(file_name));
|
||||
app->bad_usb_script = bad_usb_script_open(app->file_path);
|
||||
|
||||
string_clear(file_name);
|
||||
furi_string_free(file_name);
|
||||
|
||||
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
|
||||
|
||||
|
@ -19,12 +19,12 @@ typedef struct {
|
||||
static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
BadUsbModel* model = _model;
|
||||
|
||||
string_t disp_str;
|
||||
string_init_set_str(disp_str, model->file_name);
|
||||
FuriString* disp_str;
|
||||
disp_str = furi_string_alloc_set(model->file_name);
|
||||
elements_string_fit_width(canvas, disp_str, 128 - 2);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 8, string_get_cstr(disp_str));
|
||||
string_reset(disp_str);
|
||||
canvas_draw_str(canvas, 2, 8, furi_string_get_cstr(disp_str));
|
||||
furi_string_reset(disp_str);
|
||||
|
||||
canvas_draw_icon(canvas, 22, 20, &I_UsbTree_48x22);
|
||||
|
||||
@ -49,10 +49,10 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 127, 33, AlignRight, AlignBottom, "ERROR:");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
string_printf(disp_str, "line %u", model->state.error_line);
|
||||
furi_string_printf(disp_str, "line %u", model->state.error_line);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 127, 46, AlignRight, AlignBottom, string_get_cstr(disp_str));
|
||||
string_reset(disp_str);
|
||||
canvas, 127, 46, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
|
||||
furi_string_reset(disp_str);
|
||||
} else if(model->state.state == BadUsbStateIdle) {
|
||||
canvas_draw_icon(canvas, 4, 22, &I_Smile_18x18);
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
@ -65,16 +65,17 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_draw_icon(canvas, 4, 19, &I_EviSmile2_18x21);
|
||||
}
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
string_printf(disp_str, "%u", ((model->state.line_cur - 1) * 100) / model->state.line_nb);
|
||||
furi_string_printf(
|
||||
disp_str, "%u", ((model->state.line_cur - 1) * 100) / model->state.line_nb);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 114, 36, AlignRight, AlignBottom, string_get_cstr(disp_str));
|
||||
string_reset(disp_str);
|
||||
canvas, 114, 36, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
|
||||
furi_string_reset(disp_str);
|
||||
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
|
||||
} else if(model->state.state == BadUsbStateDone) {
|
||||
canvas_draw_icon(canvas, 4, 19, &I_EviSmile1_18x21);
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
canvas_draw_str_aligned(canvas, 114, 36, AlignRight, AlignBottom, "100");
|
||||
string_reset(disp_str);
|
||||
furi_string_reset(disp_str);
|
||||
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
|
||||
} else if(model->state.state == BadUsbStateDelay) {
|
||||
if(model->anim_frame == 0) {
|
||||
@ -83,21 +84,22 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_draw_icon(canvas, 4, 19, &I_EviWaiting2_18x21);
|
||||
}
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
string_printf(disp_str, "%u", ((model->state.line_cur - 1) * 100) / model->state.line_nb);
|
||||
furi_string_printf(
|
||||
disp_str, "%u", ((model->state.line_cur - 1) * 100) / model->state.line_nb);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 114, 36, AlignRight, AlignBottom, string_get_cstr(disp_str));
|
||||
string_reset(disp_str);
|
||||
canvas, 114, 36, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
|
||||
furi_string_reset(disp_str);
|
||||
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
string_printf(disp_str, "delay %us", model->state.delay_remain);
|
||||
furi_string_printf(disp_str, "delay %us", model->state.delay_remain);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 127, 46, AlignRight, AlignBottom, string_get_cstr(disp_str));
|
||||
string_reset(disp_str);
|
||||
canvas, 127, 46, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
|
||||
furi_string_reset(disp_str);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 4, 22, &I_Clock_18x18);
|
||||
}
|
||||
|
||||
string_clear(disp_str);
|
||||
furi_string_free(disp_str);
|
||||
}
|
||||
|
||||
static bool bad_usb_input_callback(InputEvent* event, void* context) {
|
||||
|
@ -14,21 +14,24 @@ typedef struct {
|
||||
Storage* storage;
|
||||
DialogsApp* dialogs;
|
||||
Gui* gui;
|
||||
string_t fap_path;
|
||||
FuriString* fap_path;
|
||||
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Loading* loading;
|
||||
} FapLoader;
|
||||
|
||||
static bool
|
||||
fap_loader_item_callback(string_t path, void* context, uint8_t** icon_ptr, string_t item_name) {
|
||||
static bool fap_loader_item_callback(
|
||||
FuriString* path,
|
||||
void* context,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name) {
|
||||
FapLoader* loader = context;
|
||||
furi_assert(loader);
|
||||
|
||||
FlipperApplication* app = flipper_application_alloc(loader->storage, &hashtable_api_interface);
|
||||
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload_manifest(app, string_get_cstr(path));
|
||||
flipper_application_preload_manifest(app, furi_string_get_cstr(path));
|
||||
|
||||
bool load_success = false;
|
||||
|
||||
@ -37,10 +40,10 @@ static bool
|
||||
if(manifest->has_icon) {
|
||||
memcpy(*icon_ptr, manifest->icon, FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
}
|
||||
string_set_str(item_name, manifest->name);
|
||||
furi_string_set(item_name, manifest->name);
|
||||
load_success = true;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "FAP Loader failed to preload %s", string_get_cstr(path));
|
||||
FURI_LOG_E(TAG, "FAP Loader failed to preload %s", furi_string_get_cstr(path));
|
||||
load_success = false;
|
||||
}
|
||||
|
||||
@ -51,9 +54,9 @@ static bool
|
||||
static bool fap_loader_run_selected_app(FapLoader* loader) {
|
||||
furi_assert(loader);
|
||||
|
||||
string_t error_message;
|
||||
FuriString* error_message;
|
||||
|
||||
string_init_set(error_message, "unknown error");
|
||||
error_message = furi_string_alloc_set("unknown error");
|
||||
|
||||
bool file_selected = false;
|
||||
bool show_error = true;
|
||||
@ -61,17 +64,17 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
|
||||
file_selected = true;
|
||||
loader->app = flipper_application_alloc(loader->storage, &hashtable_api_interface);
|
||||
|
||||
FURI_LOG_I(TAG, "FAP Loader is loading %s", string_get_cstr(loader->fap_path));
|
||||
FURI_LOG_I(TAG, "FAP Loader is loading %s", furi_string_get_cstr(loader->fap_path));
|
||||
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload(loader->app, string_get_cstr(loader->fap_path));
|
||||
flipper_application_preload(loader->app, furi_string_get_cstr(loader->fap_path));
|
||||
if(preload_res != FlipperApplicationPreloadStatusSuccess) {
|
||||
const char* err_msg = flipper_application_preload_status_to_string(preload_res);
|
||||
string_printf(error_message, "Preload failed: %s", err_msg);
|
||||
furi_string_printf(error_message, "Preload failed: %s", err_msg);
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"FAP Loader failed to preload %s: %s",
|
||||
string_get_cstr(loader->fap_path),
|
||||
furi_string_get_cstr(loader->fap_path),
|
||||
err_msg);
|
||||
break;
|
||||
}
|
||||
@ -80,11 +83,11 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
|
||||
FlipperApplicationLoadStatus load_status = flipper_application_map_to_memory(loader->app);
|
||||
if(load_status != FlipperApplicationLoadStatusSuccess) {
|
||||
const char* err_msg = flipper_application_load_status_to_string(load_status);
|
||||
string_printf(error_message, "Load failed: %s", err_msg);
|
||||
furi_string_printf(error_message, "Load failed: %s", err_msg);
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"FAP Loader failed to map to memory %s: %s",
|
||||
string_get_cstr(loader->fap_path),
|
||||
furi_string_get_cstr(loader->fap_path),
|
||||
err_msg);
|
||||
break;
|
||||
}
|
||||
@ -106,19 +109,19 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
|
||||
dialog_message_set_header(message, "Error", 64, 0, AlignCenter, AlignTop);
|
||||
dialog_message_set_buttons(message, NULL, NULL, NULL);
|
||||
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
string_printf(buffer, "%s", string_get_cstr(error_message));
|
||||
string_replace_str(buffer, ":", "\n");
|
||||
FuriString* buffer;
|
||||
buffer = furi_string_alloc();
|
||||
furi_string_printf(buffer, "%s", furi_string_get_cstr(error_message));
|
||||
furi_string_replace(buffer, ":", "\n");
|
||||
dialog_message_set_text(
|
||||
message, string_get_cstr(buffer), 64, 32, AlignCenter, AlignCenter);
|
||||
message, furi_string_get_cstr(buffer), 64, 32, AlignCenter, AlignCenter);
|
||||
|
||||
dialog_message_show(loader->dialogs, message);
|
||||
dialog_message_free(message);
|
||||
string_clear(buffer);
|
||||
furi_string_free(buffer);
|
||||
}
|
||||
|
||||
string_clear(error_message);
|
||||
furi_string_free(error_message);
|
||||
|
||||
if(file_selected) {
|
||||
flipper_application_free(loader->app);
|
||||
@ -155,10 +158,10 @@ int32_t fap_loader_app(void* p) {
|
||||
view_dispatcher_add_view(loader->view_dispatcher, 0, loading_get_view(loader->loading));
|
||||
|
||||
if(p) {
|
||||
string_init_set(loader->fap_path, (const char*)p);
|
||||
loader->fap_path = furi_string_alloc_set((const char*)p);
|
||||
fap_loader_run_selected_app(loader);
|
||||
} else {
|
||||
string_init_set(loader->fap_path, EXT_PATH("apps"));
|
||||
loader->fap_path = furi_string_alloc_set(EXT_PATH("apps"));
|
||||
|
||||
while(fap_loader_select_app(loader)) {
|
||||
view_dispatcher_switch_to_view(loader->view_dispatcher, 0);
|
||||
@ -170,7 +173,7 @@ int32_t fap_loader_app(void* p) {
|
||||
loading_free(loader->loading);
|
||||
view_dispatcher_free(loader->view_dispatcher);
|
||||
|
||||
string_clear(loader->fap_path);
|
||||
furi_string_free(loader->fap_path);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "assets_icons.h"
|
||||
#include "ibutton_i.h"
|
||||
#include "ibutton/scenes/ibutton_scene.h"
|
||||
#include "m-string.h"
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <rpc/rpc_app.h>
|
||||
@ -39,25 +38,25 @@ static void ibutton_make_app_folder(iButton* ibutton) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ibutton_load_key_data(iButton* ibutton, string_t key_path, bool show_dialog) {
|
||||
bool ibutton_load_key_data(iButton* ibutton, FuriString* key_path, bool show_dialog) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(ibutton->storage);
|
||||
bool result = false;
|
||||
string_t data;
|
||||
string_init(data);
|
||||
FuriString* data;
|
||||
data = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(file, string_get_cstr(key_path))) break;
|
||||
if(!flipper_format_file_open_existing(file, furi_string_get_cstr(key_path))) break;
|
||||
|
||||
// header
|
||||
uint32_t version;
|
||||
if(!flipper_format_read_header(file, data, &version)) break;
|
||||
if(string_cmp_str(data, IBUTTON_APP_FILE_TYPE) != 0) break;
|
||||
if(furi_string_cmp_str(data, IBUTTON_APP_FILE_TYPE) != 0) break;
|
||||
if(version != 1) break;
|
||||
|
||||
// key type
|
||||
iButtonKeyType type;
|
||||
if(!flipper_format_read_string(file, "Key type", data)) break;
|
||||
if(!ibutton_key_get_type_by_string(string_get_cstr(data), &type)) break;
|
||||
if(!ibutton_key_get_type_by_string(furi_string_get_cstr(data), &type)) break;
|
||||
|
||||
// key data
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
|
||||
@ -71,7 +70,7 @@ bool ibutton_load_key_data(iButton* ibutton, string_t key_path, bool show_dialog
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(file);
|
||||
string_clear(data);
|
||||
furi_string_free(data);
|
||||
|
||||
if((!result) && (show_dialog)) {
|
||||
dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file");
|
||||
@ -119,7 +118,7 @@ void ibutton_tick_event_callback(void* context) {
|
||||
iButton* ibutton_alloc() {
|
||||
iButton* ibutton = malloc(sizeof(iButton));
|
||||
|
||||
string_init(ibutton->file_path);
|
||||
ibutton->file_path = furi_string_alloc();
|
||||
|
||||
ibutton->scene_manager = scene_manager_alloc(&ibutton_scene_handlers, ibutton);
|
||||
|
||||
@ -210,7 +209,7 @@ void ibutton_free(iButton* ibutton) {
|
||||
ibutton_worker_free(ibutton->key_worker);
|
||||
ibutton_key_free(ibutton->key);
|
||||
|
||||
string_clear(ibutton->file_path);
|
||||
furi_string_free(ibutton->file_path);
|
||||
|
||||
free(ibutton);
|
||||
}
|
||||
@ -240,19 +239,19 @@ bool ibutton_save_key(iButton* ibutton, const char* key_name) {
|
||||
|
||||
do {
|
||||
// Check if we has old key
|
||||
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
// First remove old key
|
||||
ibutton_delete_key(ibutton);
|
||||
|
||||
// Remove old key name from path
|
||||
size_t filename_start = string_search_rchar(ibutton->file_path, '/');
|
||||
string_left(ibutton->file_path, filename_start);
|
||||
size_t filename_start = furi_string_search_rchar(ibutton->file_path, '/');
|
||||
furi_string_left(ibutton->file_path, filename_start);
|
||||
}
|
||||
|
||||
string_cat_printf(ibutton->file_path, "/%s%s", key_name, IBUTTON_APP_EXTENSION);
|
||||
furi_string_cat_printf(ibutton->file_path, "/%s%s", key_name, IBUTTON_APP_EXTENSION);
|
||||
|
||||
// Open file for write
|
||||
if(!flipper_format_file_open_always(file, string_get_cstr(ibutton->file_path))) break;
|
||||
if(!flipper_format_file_open_always(file, furi_string_get_cstr(ibutton->file_path))) break;
|
||||
|
||||
// Write header
|
||||
if(!flipper_format_write_header_cstr(file, IBUTTON_APP_FILE_TYPE, 1)) break;
|
||||
@ -286,7 +285,7 @@ bool ibutton_save_key(iButton* ibutton, const char* key_name) {
|
||||
|
||||
bool ibutton_delete_key(iButton* ibutton) {
|
||||
bool result = false;
|
||||
result = storage_simply_remove(ibutton->storage, string_get_cstr(ibutton->file_path));
|
||||
result = storage_simply_remove(ibutton->storage, furi_string_get_cstr(ibutton->file_path));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -326,7 +325,7 @@ int32_t ibutton_app(void* p) {
|
||||
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
|
||||
rpc_system_app_send_started(ibutton->rpc_ctx);
|
||||
} else {
|
||||
string_set_str(ibutton->file_path, (const char*)p);
|
||||
furi_string_set(ibutton->file_path, (const char*)p);
|
||||
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
|
||||
key_loaded = true;
|
||||
// TODO: Display an error if the key from p could not be loaded
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <one_wire/one_wire_host.h>
|
||||
|
||||
static void ibutton_cli(Cli* cli, string_t args, void* context);
|
||||
static void onewire_cli(Cli* cli, string_t args, void* context);
|
||||
static void ibutton_cli(Cli* cli, FuriString* args, void* context);
|
||||
static void onewire_cli(Cli* cli, FuriString* args, void* context);
|
||||
|
||||
// app cli function
|
||||
void ibutton_on_system_start() {
|
||||
@ -34,16 +34,16 @@ void ibutton_cli_print_usage() {
|
||||
printf("\t<key_data> are hex-formatted\r\n");
|
||||
};
|
||||
|
||||
bool ibutton_cli_get_key_type(string_t data, iButtonKeyType* type) {
|
||||
bool ibutton_cli_get_key_type(FuriString* data, iButtonKeyType* type) {
|
||||
bool result = false;
|
||||
|
||||
if(string_cmp_str(data, "Dallas") == 0 || string_cmp_str(data, "dallas") == 0) {
|
||||
if(furi_string_cmp_str(data, "Dallas") == 0 || furi_string_cmp_str(data, "dallas") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyDS1990;
|
||||
} else if(string_cmp_str(data, "Cyfral") == 0 || string_cmp_str(data, "cyfral") == 0) {
|
||||
} else if(furi_string_cmp_str(data, "Cyfral") == 0 || furi_string_cmp_str(data, "cyfral") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyCyfral;
|
||||
} else if(string_cmp_str(data, "Metakom") == 0 || string_cmp_str(data, "metakom") == 0) {
|
||||
} else if(furi_string_cmp_str(data, "Metakom") == 0 || furi_string_cmp_str(data, "metakom") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyMetakom;
|
||||
}
|
||||
@ -123,17 +123,17 @@ static void ibutton_cli_worker_write_cb(void* context, iButtonWorkerWriteResult
|
||||
furi_event_flag_set(write_context->event, EVENT_FLAG_IBUTTON_COMPLETE);
|
||||
}
|
||||
|
||||
void ibutton_cli_write(Cli* cli, string_t args) {
|
||||
void ibutton_cli_write(Cli* cli, FuriString* args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
iButtonWriteContext write_context;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
string_t data;
|
||||
FuriString* data;
|
||||
|
||||
write_context.event = furi_event_flag_alloc();
|
||||
|
||||
string_init(data);
|
||||
data = furi_string_alloc();
|
||||
ibutton_worker_start_thread(worker);
|
||||
ibutton_worker_write_set_callback(worker, ibutton_cli_worker_write_cb, &write_context);
|
||||
|
||||
@ -186,7 +186,7 @@ void ibutton_cli_write(Cli* cli, string_t args) {
|
||||
ibutton_worker_stop(worker);
|
||||
} while(false);
|
||||
|
||||
string_clear(data);
|
||||
furi_string_free(data);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_key_free(key);
|
||||
@ -194,14 +194,14 @@ void ibutton_cli_write(Cli* cli, string_t args) {
|
||||
furi_event_flag_free(write_context.event);
|
||||
};
|
||||
|
||||
void ibutton_cli_emulate(Cli* cli, string_t args) {
|
||||
void ibutton_cli_emulate(Cli* cli, FuriString* args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
string_t data;
|
||||
FuriString* data;
|
||||
|
||||
string_init(data);
|
||||
data = furi_string_alloc();
|
||||
ibutton_worker_start_thread(worker);
|
||||
|
||||
do {
|
||||
@ -234,34 +234,34 @@ void ibutton_cli_emulate(Cli* cli, string_t args) {
|
||||
ibutton_worker_stop(worker);
|
||||
} while(false);
|
||||
|
||||
string_clear(data);
|
||||
furi_string_free(data);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_key_free(key);
|
||||
};
|
||||
|
||||
static void ibutton_cli(Cli* cli, string_t args, void* context) {
|
||||
static void ibutton_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
FuriString* cmd;
|
||||
cmd = furi_string_alloc();
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
ibutton_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "read") == 0) {
|
||||
ibutton_cli_read(cli);
|
||||
} else if(string_cmp_str(cmd, "write") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "write") == 0) {
|
||||
ibutton_cli_write(cli, args);
|
||||
} else if(string_cmp_str(cmd, "emulate") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "emulate") == 0) {
|
||||
ibutton_cli_emulate(cli, args);
|
||||
} else {
|
||||
ibutton_cli_print_usage();
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
void onewire_cli_print_usage() {
|
||||
@ -299,20 +299,20 @@ static void onewire_cli_search(Cli* cli) {
|
||||
onewire_host_free(onewire);
|
||||
}
|
||||
|
||||
void onewire_cli(Cli* cli, string_t args, void* context) {
|
||||
void onewire_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
FuriString* cmd;
|
||||
cmd = furi_string_alloc();
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
onewire_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "search") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "search") == 0) {
|
||||
onewire_cli_search(cli);
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ struct iButton {
|
||||
iButtonWorker* key_worker;
|
||||
iButtonKey* key;
|
||||
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
char text_store[IBUTTON_TEXT_STORE_SIZE + 1];
|
||||
|
||||
Submenu* submenu;
|
||||
@ -78,7 +78,7 @@ typedef enum {
|
||||
} iButtonNotificationMessage;
|
||||
|
||||
bool ibutton_file_select(iButton* ibutton);
|
||||
bool ibutton_load_key_data(iButton* ibutton, string_t key_path, bool show_dialog);
|
||||
bool ibutton_load_key_data(iButton* ibutton, FuriString* key_path, bool show_dialog);
|
||||
bool ibutton_save_key(iButton* ibutton, const char* key_name);
|
||||
bool ibutton_delete_key(iButton* ibutton);
|
||||
void ibutton_text_store_set(iButton* ibutton, const char* text, ...);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "../ibutton_i.h"
|
||||
#include "m-string.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexCyfral,
|
||||
@ -47,7 +46,7 @@ bool ibutton_scene_add_type_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_crash("Unknown key type");
|
||||
}
|
||||
|
||||
string_set_str(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
ibutton_key_clear_data(key);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneAddValue);
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ void ibutton_scene_delete_confirm_on_enter(void* context) {
|
||||
iButtonKey* key = ibutton->key;
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
|
||||
ibutton_text_store_set(ibutton, "\e#Delete %s?\e#", string_get_cstr(key_name));
|
||||
ibutton_text_store_set(ibutton, "\e#Delete %s?\e#", furi_string_get_cstr(key_name));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
widget_add_button_element(
|
||||
@ -68,7 +68,7 @@ void ibutton_scene_delete_confirm_on_enter(void* context) {
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
string_clear(key_name);
|
||||
furi_string_free(key_name);
|
||||
}
|
||||
|
||||
bool ibutton_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -20,17 +20,17 @@ void ibutton_scene_emulate_on_enter(void* context) {
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
|
||||
// check that stored key has name
|
||||
if(!string_empty_p(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name));
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
@ -69,7 +69,7 @@ void ibutton_scene_emulate_on_enter(void* context) {
|
||||
ibutton->key_worker, ibutton_scene_emulate_callback, ibutton);
|
||||
ibutton_worker_emulate_start(ibutton->key_worker, key);
|
||||
|
||||
string_clear(key_name);
|
||||
furi_string_free(key_name);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ void ibutton_scene_info_on_enter(void* context) {
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
|
||||
ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name));
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 23, AlignCenter, AlignCenter, ibutton->text_store, true);
|
||||
|
||||
@ -50,7 +50,7 @@ void ibutton_scene_info_on_enter(void* context) {
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
||||
|
||||
string_clear(key_name);
|
||||
furi_string_free(key_name);
|
||||
}
|
||||
|
||||
bool ibutton_scene_info_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -18,7 +18,7 @@ void ibutton_scene_read_on_enter(void* context) {
|
||||
popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
|
||||
string_set_str(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
|
||||
ibutton_worker_read_set_callback(worker, ibutton_scene_read_callback, ibutton);
|
||||
ibutton_worker_read_start(worker, key);
|
||||
|
@ -29,19 +29,19 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.event == iButtonCustomEventRpcLoad) {
|
||||
const char* arg = rpc_system_app_get_data(ibutton->rpc_ctx);
|
||||
bool result = false;
|
||||
if(arg && (string_empty_p(ibutton->file_path))) {
|
||||
string_set_str(ibutton->file_path, arg);
|
||||
if(arg && (furi_string_empty(ibutton->file_path))) {
|
||||
furi_string_set(ibutton->file_path, arg);
|
||||
if(ibutton_load_key_data(ibutton, ibutton->file_path, false)) {
|
||||
ibutton_worker_emulate_start(ibutton->key_worker, ibutton->key);
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
|
||||
if(!string_empty_p(key_name)) {
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(
|
||||
ibutton, "emulating\n%s", string_get_cstr(key_name));
|
||||
ibutton, "emulating\n%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
ibutton_text_store_set(ibutton, "emulating");
|
||||
}
|
||||
@ -49,10 +49,10 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
|
||||
string_clear(key_name);
|
||||
furi_string_free(key_name);
|
||||
result = true;
|
||||
} else {
|
||||
string_reset(ibutton->file_path);
|
||||
furi_string_reset(ibutton->file_path);
|
||||
}
|
||||
}
|
||||
rpc_system_app_confirm(ibutton->rpc_ctx, RpcAppEventLoadFile, result);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "../ibutton_i.h"
|
||||
#include "m-string.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include <toolbox/path.h>
|
||||
|
||||
@ -12,17 +11,17 @@ void ibutton_scene_save_name_on_enter(void* context) {
|
||||
iButton* ibutton = context;
|
||||
TextInput* text_input = ibutton->text_input;
|
||||
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
|
||||
const bool key_name_is_empty = string_empty_p(key_name);
|
||||
const bool key_name_is_empty = furi_string_empty(key_name);
|
||||
if(key_name_is_empty) {
|
||||
set_random_name(ibutton->text_store, IBUTTON_TEXT_STORE_SIZE);
|
||||
} else {
|
||||
ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name));
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
}
|
||||
|
||||
text_input_set_header_text(text_input, "Name the key");
|
||||
@ -34,19 +33,19 @@ void ibutton_scene_save_name_on_enter(void* context) {
|
||||
IBUTTON_KEY_NAME_SIZE,
|
||||
key_name_is_empty);
|
||||
|
||||
string_t folder_path;
|
||||
string_init(folder_path);
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
path_extract_dirname(string_get_cstr(ibutton->file_path), folder_path);
|
||||
path_extract_dirname(furi_string_get_cstr(ibutton->file_path), folder_path);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
string_get_cstr(folder_path), IBUTTON_APP_EXTENSION, string_get_cstr(key_name));
|
||||
furi_string_get_cstr(folder_path), IBUTTON_APP_EXTENSION, furi_string_get_cstr(key_name));
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewTextInput);
|
||||
|
||||
string_clear(key_name);
|
||||
string_clear(folder_path);
|
||||
furi_string_free(key_name);
|
||||
furi_string_free(folder_path);
|
||||
}
|
||||
|
||||
bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -39,7 +39,7 @@ bool ibutton_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRead);
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
string_set_str(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
furi_string_set(ibutton->file_path, IBUTTON_APP_FOLDER);
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSelectKey);
|
||||
} else if(event.event == SubmenuIndexAdd) {
|
||||
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneAddType);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "../ibutton_i.h"
|
||||
#include "m-string.h"
|
||||
#include "toolbox/path.h"
|
||||
|
||||
typedef enum {
|
||||
@ -20,15 +19,15 @@ void ibutton_scene_write_on_enter(void* context) {
|
||||
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
string_t key_name;
|
||||
string_init(key_name);
|
||||
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
FuriString* key_name;
|
||||
key_name = furi_string_alloc();
|
||||
if(furi_string_end_with(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
|
||||
path_extract_filename(ibutton->file_path, key_name, true);
|
||||
}
|
||||
|
||||
// check that stored key has name
|
||||
if(!string_empty_p(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name));
|
||||
if(!furi_string_empty(key_name)) {
|
||||
ibutton_text_store_set(ibutton, "%s", furi_string_get_cstr(key_name));
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
@ -66,7 +65,7 @@ void ibutton_scene_write_on_enter(void* context) {
|
||||
ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton);
|
||||
ibutton_worker_write_start(worker, key);
|
||||
|
||||
string_clear(key_name);
|
||||
furi_string_free(key_name);
|
||||
|
||||
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
||||
}
|
||||
|
@ -65,51 +65,52 @@ static void infrared_rpc_command_callback(RpcAppSystemEvent event, void* context
|
||||
}
|
||||
}
|
||||
|
||||
static void infrared_find_vacant_remote_name(string_t name, const char* path) {
|
||||
static void infrared_find_vacant_remote_name(FuriString* name, const char* path) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
string_t base_path;
|
||||
string_init_set_str(base_path, path);
|
||||
FuriString* base_path;
|
||||
base_path = furi_string_alloc_set(path);
|
||||
|
||||
if(string_end_with_str_p(base_path, INFRARED_APP_EXTENSION)) {
|
||||
size_t filename_start = string_search_rchar(base_path, '/');
|
||||
string_left(base_path, filename_start);
|
||||
if(furi_string_end_with(base_path, INFRARED_APP_EXTENSION)) {
|
||||
size_t filename_start = furi_string_search_rchar(base_path, '/');
|
||||
furi_string_left(base_path, filename_start);
|
||||
}
|
||||
|
||||
string_printf(base_path, "%s/%s%s", path, string_get_cstr(name), INFRARED_APP_EXTENSION);
|
||||
furi_string_printf(
|
||||
base_path, "%s/%s%s", path, furi_string_get_cstr(name), INFRARED_APP_EXTENSION);
|
||||
|
||||
FS_Error status = storage_common_stat(storage, string_get_cstr(base_path), NULL);
|
||||
FS_Error status = storage_common_stat(storage, furi_string_get_cstr(base_path), NULL);
|
||||
|
||||
if(status == FSE_OK) {
|
||||
/* If the suggested name is occupied, try another one (name2, name3, etc) */
|
||||
size_t dot = string_search_rchar(base_path, '.');
|
||||
string_left(base_path, dot);
|
||||
size_t dot = furi_string_search_rchar(base_path, '.');
|
||||
furi_string_left(base_path, dot);
|
||||
|
||||
string_t path_temp;
|
||||
string_init(path_temp);
|
||||
FuriString* path_temp;
|
||||
path_temp = furi_string_alloc();
|
||||
|
||||
uint32_t i = 1;
|
||||
do {
|
||||
string_printf(
|
||||
path_temp, "%s%u%s", string_get_cstr(base_path), ++i, INFRARED_APP_EXTENSION);
|
||||
status = storage_common_stat(storage, string_get_cstr(path_temp), NULL);
|
||||
furi_string_printf(
|
||||
path_temp, "%s%u%s", furi_string_get_cstr(base_path), ++i, INFRARED_APP_EXTENSION);
|
||||
status = storage_common_stat(storage, furi_string_get_cstr(path_temp), NULL);
|
||||
} while(status == FSE_OK);
|
||||
|
||||
string_clear(path_temp);
|
||||
furi_string_free(path_temp);
|
||||
|
||||
if(status == FSE_NOT_EXIST) {
|
||||
string_cat_printf(name, "%u", i);
|
||||
furi_string_cat_printf(name, "%u", i);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(base_path);
|
||||
furi_string_free(base_path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static Infrared* infrared_alloc() {
|
||||
Infrared* infrared = malloc(sizeof(Infrared));
|
||||
|
||||
string_init(infrared->file_path);
|
||||
infrared->file_path = furi_string_alloc();
|
||||
|
||||
InfraredAppState* app_state = &infrared->app_state;
|
||||
app_state->is_learning_new_remote = false;
|
||||
@ -232,7 +233,7 @@ static void infrared_free(Infrared* infrared) {
|
||||
furi_record_close(RECORD_GUI);
|
||||
infrared->gui = NULL;
|
||||
|
||||
string_clear(infrared->file_path);
|
||||
furi_string_free(infrared->file_path);
|
||||
|
||||
free(infrared);
|
||||
}
|
||||
@ -243,19 +244,20 @@ bool infrared_add_remote_with_button(
|
||||
InfraredSignal* signal) {
|
||||
InfraredRemote* remote = infrared->remote;
|
||||
|
||||
string_t new_name, new_path;
|
||||
string_init_set_str(new_name, INFRARED_DEFAULT_REMOTE_NAME);
|
||||
string_init_set_str(new_path, INFRARED_APP_FOLDER);
|
||||
FuriString *new_name, *new_path;
|
||||
new_name = furi_string_alloc_set(INFRARED_DEFAULT_REMOTE_NAME);
|
||||
new_path = furi_string_alloc_set(INFRARED_APP_FOLDER);
|
||||
|
||||
infrared_find_vacant_remote_name(new_name, string_get_cstr(new_path));
|
||||
string_cat_printf(new_path, "/%s%s", string_get_cstr(new_name), INFRARED_APP_EXTENSION);
|
||||
infrared_find_vacant_remote_name(new_name, furi_string_get_cstr(new_path));
|
||||
furi_string_cat_printf(
|
||||
new_path, "/%s%s", furi_string_get_cstr(new_name), INFRARED_APP_EXTENSION);
|
||||
|
||||
infrared_remote_reset(remote);
|
||||
infrared_remote_set_name(remote, string_get_cstr(new_name));
|
||||
infrared_remote_set_path(remote, string_get_cstr(new_path));
|
||||
infrared_remote_set_name(remote, furi_string_get_cstr(new_name));
|
||||
infrared_remote_set_path(remote, furi_string_get_cstr(new_path));
|
||||
|
||||
string_clear(new_name);
|
||||
string_clear(new_path);
|
||||
furi_string_free(new_name);
|
||||
furi_string_free(new_path);
|
||||
return infrared_remote_add_button(remote, button_name, signal);
|
||||
}
|
||||
|
||||
@ -267,28 +269,29 @@ bool infrared_rename_current_remote(Infrared* infrared, const char* name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
string_t new_name;
|
||||
string_init_set_str(new_name, name);
|
||||
FuriString* new_name;
|
||||
new_name = furi_string_alloc_set(name);
|
||||
|
||||
infrared_find_vacant_remote_name(new_name, remote_path);
|
||||
|
||||
string_t new_path;
|
||||
string_init_set(new_path, infrared_remote_get_path(remote));
|
||||
if(string_end_with_str_p(new_path, INFRARED_APP_EXTENSION)) {
|
||||
size_t filename_start = string_search_rchar(new_path, '/');
|
||||
string_left(new_path, filename_start);
|
||||
FuriString* new_path;
|
||||
new_path = furi_string_alloc_set(infrared_remote_get_path(remote));
|
||||
if(furi_string_end_with(new_path, INFRARED_APP_EXTENSION)) {
|
||||
size_t filename_start = furi_string_search_rchar(new_path, '/');
|
||||
furi_string_left(new_path, filename_start);
|
||||
}
|
||||
string_cat_printf(new_path, "/%s%s", string_get_cstr(new_name), INFRARED_APP_EXTENSION);
|
||||
furi_string_cat_printf(
|
||||
new_path, "/%s%s", furi_string_get_cstr(new_name), INFRARED_APP_EXTENSION);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FS_Error status = storage_common_rename(
|
||||
storage, infrared_remote_get_path(remote), string_get_cstr(new_path));
|
||||
infrared_remote_set_name(remote, string_get_cstr(new_name));
|
||||
infrared_remote_set_path(remote, string_get_cstr(new_path));
|
||||
storage, infrared_remote_get_path(remote), furi_string_get_cstr(new_path));
|
||||
infrared_remote_set_name(remote, furi_string_get_cstr(new_name));
|
||||
infrared_remote_set_path(remote, furi_string_get_cstr(new_path));
|
||||
|
||||
string_clear(new_name);
|
||||
string_clear(new_path);
|
||||
furi_string_free(new_name);
|
||||
furi_string_free(new_path);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return (status == FSE_OK || status == FSE_EXIST);
|
||||
@ -435,7 +438,7 @@ int32_t infrared_app(void* p) {
|
||||
rpc_system_app_send_started(infrared->rpc_ctx);
|
||||
is_rpc_mode = true;
|
||||
} else {
|
||||
string_set_str(infrared->file_path, (const char*)p);
|
||||
furi_string_set(infrared->file_path, (const char*)p);
|
||||
is_remote_loaded = infrared_remote_load(infrared->remote, infrared->file_path);
|
||||
if(!is_remote_loaded) {
|
||||
dialog_message_show_storage_error(
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <m-dict.h>
|
||||
#include <m-string.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#include "infrared_signal.h"
|
||||
@ -14,15 +13,15 @@ typedef struct {
|
||||
|
||||
DICT_DEF2(
|
||||
InfraredBruteForceRecordDict,
|
||||
string_t,
|
||||
STRING_OPLIST,
|
||||
FuriString*,
|
||||
FURI_STRING_OPLIST,
|
||||
InfraredBruteForceRecord,
|
||||
M_POD_OPLIST);
|
||||
|
||||
struct InfraredBruteForce {
|
||||
FlipperFormat* ff;
|
||||
const char* db_filename;
|
||||
string_t current_record_name;
|
||||
FuriString* current_record_name;
|
||||
InfraredSignal* current_signal;
|
||||
InfraredBruteForceRecordDict_t records;
|
||||
bool is_started;
|
||||
@ -34,7 +33,7 @@ InfraredBruteForce* infrared_brute_force_alloc() {
|
||||
brute_force->db_filename = NULL;
|
||||
brute_force->current_signal = NULL;
|
||||
brute_force->is_started = false;
|
||||
string_init(brute_force->current_record_name);
|
||||
brute_force->current_record_name = furi_string_alloc();
|
||||
InfraredBruteForceRecordDict_init(brute_force->records);
|
||||
return brute_force;
|
||||
}
|
||||
@ -42,7 +41,7 @@ InfraredBruteForce* infrared_brute_force_alloc() {
|
||||
void infrared_brute_force_free(InfraredBruteForce* brute_force) {
|
||||
furi_assert(!brute_force->is_started);
|
||||
InfraredBruteForceRecordDict_clear(brute_force->records);
|
||||
string_clear(brute_force->current_record_name);
|
||||
furi_string_free(brute_force->current_record_name);
|
||||
free(brute_force);
|
||||
}
|
||||
|
||||
@ -61,8 +60,8 @@ bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
|
||||
|
||||
success = flipper_format_buffered_file_open_existing(ff, brute_force->db_filename);
|
||||
if(success) {
|
||||
string_t signal_name;
|
||||
string_init(signal_name);
|
||||
FuriString* signal_name;
|
||||
signal_name = furi_string_alloc();
|
||||
while(flipper_format_read_string(ff, "name", signal_name)) {
|
||||
InfraredBruteForceRecord* record =
|
||||
InfraredBruteForceRecordDict_get(brute_force->records, signal_name);
|
||||
@ -70,7 +69,7 @@ bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
|
||||
++(record->count);
|
||||
}
|
||||
}
|
||||
string_clear(signal_name);
|
||||
furi_string_free(signal_name);
|
||||
}
|
||||
|
||||
flipper_format_free(ff);
|
||||
@ -94,7 +93,7 @@ bool infrared_brute_force_start(
|
||||
if(record->value.index == index) {
|
||||
*record_count = record->value.count;
|
||||
if(*record_count) {
|
||||
string_set(brute_force->current_record_name, record->key);
|
||||
furi_string_set(brute_force->current_record_name, record->key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -118,7 +117,7 @@ bool infrared_brute_force_is_started(InfraredBruteForce* brute_force) {
|
||||
|
||||
void infrared_brute_force_stop(InfraredBruteForce* brute_force) {
|
||||
furi_assert(brute_force->is_started);
|
||||
string_reset(brute_force->current_record_name);
|
||||
furi_string_reset(brute_force->current_record_name);
|
||||
infrared_signal_free(brute_force->current_signal);
|
||||
flipper_format_free(brute_force->ff);
|
||||
brute_force->current_signal = NULL;
|
||||
@ -142,10 +141,10 @@ void infrared_brute_force_add_record(
|
||||
uint32_t index,
|
||||
const char* name) {
|
||||
InfraredBruteForceRecord value = {.index = index, .count = 0};
|
||||
string_t key;
|
||||
string_init_set_str(key, name);
|
||||
FuriString* key;
|
||||
key = furi_string_alloc_set(name);
|
||||
InfraredBruteForceRecordDict_set_at(brute_force->records, key, value);
|
||||
string_clear(key);
|
||||
furi_string_free(key);
|
||||
}
|
||||
|
||||
void infrared_brute_force_reset(InfraredBruteForce* brute_force) {
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <m-string.h>
|
||||
#include <cli/cli.h>
|
||||
#include <infrared.h>
|
||||
#include <infrared_worker.h>
|
||||
@ -10,13 +9,13 @@
|
||||
|
||||
#define INFRARED_CLI_BUF_SIZE 10
|
||||
|
||||
static void infrared_cli_start_ir_rx(Cli* cli, string_t args);
|
||||
static void infrared_cli_start_ir_tx(Cli* cli, string_t args);
|
||||
static void infrared_cli_process_decode(Cli* cli, string_t args);
|
||||
static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args);
|
||||
static void infrared_cli_start_ir_tx(Cli* cli, FuriString* args);
|
||||
static void infrared_cli_process_decode(Cli* cli, FuriString* args);
|
||||
|
||||
static const struct {
|
||||
const char* cmd;
|
||||
void (*process_function)(Cli* cli, string_t args);
|
||||
void (*process_function)(Cli* cli, FuriString* args);
|
||||
} infrared_cli_commands[] = {
|
||||
{.cmd = "rx", .process_function = infrared_cli_start_ir_rx},
|
||||
{.cmd = "tx", .process_function = infrared_cli_start_ir_tx},
|
||||
@ -58,7 +57,7 @@ static void signal_received_callback(void* context, InfraredWorkerSignal* receiv
|
||||
}
|
||||
}
|
||||
|
||||
static void infrared_cli_start_ir_rx(Cli* cli, string_t args) {
|
||||
static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
UNUSED(args);
|
||||
InfraredWorker* worker = infrared_worker_alloc();
|
||||
@ -151,9 +150,9 @@ static bool infrared_cli_parse_raw(const char* str, InfraredSignal* signal) {
|
||||
return infrared_signal_is_valid(signal);
|
||||
}
|
||||
|
||||
static void infrared_cli_start_ir_tx(Cli* cli, string_t args) {
|
||||
static void infrared_cli_start_ir_tx(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
const char* str = string_get_cstr(args);
|
||||
const char* str = furi_string_get_cstr(args);
|
||||
InfraredSignal* signal = infrared_signal_alloc();
|
||||
|
||||
bool success = infrared_cli_parse_message(str, signal) || infrared_cli_parse_raw(str, signal);
|
||||
@ -231,8 +230,8 @@ static bool infrared_cli_decode_file(FlipperFormat* input_file, FlipperFormat* o
|
||||
InfraredSignal* signal = infrared_signal_alloc();
|
||||
InfraredDecoderHandler* decoder = infrared_alloc_decoder();
|
||||
|
||||
string_t tmp;
|
||||
string_init(tmp);
|
||||
FuriString* tmp;
|
||||
tmp = furi_string_alloc();
|
||||
|
||||
while(infrared_signal_read(signal, input_file, tmp)) {
|
||||
ret = false;
|
||||
@ -242,7 +241,7 @@ static bool infrared_cli_decode_file(FlipperFormat* input_file, FlipperFormat* o
|
||||
}
|
||||
if(!infrared_signal_is_raw(signal)) {
|
||||
if(output_file &&
|
||||
!infrared_cli_save_signal(signal, output_file, string_get_cstr(tmp))) {
|
||||
!infrared_cli_save_signal(signal, output_file, furi_string_get_cstr(tmp))) {
|
||||
break;
|
||||
} else {
|
||||
printf("Skipping decoded signal\r\n");
|
||||
@ -250,31 +249,33 @@ static bool infrared_cli_decode_file(FlipperFormat* input_file, FlipperFormat* o
|
||||
}
|
||||
}
|
||||
InfraredRawSignal* raw_signal = infrared_signal_get_raw_signal(signal);
|
||||
printf("Raw signal: %s, %u samples\r\n", string_get_cstr(tmp), raw_signal->timings_size);
|
||||
if(!infrared_cli_decode_raw_signal(raw_signal, decoder, output_file, string_get_cstr(tmp)))
|
||||
printf(
|
||||
"Raw signal: %s, %u samples\r\n", furi_string_get_cstr(tmp), raw_signal->timings_size);
|
||||
if(!infrared_cli_decode_raw_signal(
|
||||
raw_signal, decoder, output_file, furi_string_get_cstr(tmp)))
|
||||
break;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
infrared_free_decoder(decoder);
|
||||
infrared_signal_free(signal);
|
||||
string_clear(tmp);
|
||||
furi_string_free(tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void infrared_cli_process_decode(Cli* cli, string_t args) {
|
||||
static void infrared_cli_process_decode(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* input_file = flipper_format_buffered_file_alloc(storage);
|
||||
FlipperFormat* output_file = NULL;
|
||||
|
||||
uint32_t version;
|
||||
string_t tmp, header, input_path, output_path;
|
||||
string_init(tmp);
|
||||
string_init(header);
|
||||
string_init(input_path);
|
||||
string_init(output_path);
|
||||
FuriString *tmp, *header, *input_path, *output_path;
|
||||
tmp = furi_string_alloc();
|
||||
header = furi_string_alloc();
|
||||
input_path = furi_string_alloc();
|
||||
output_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!args_read_probably_quoted_string_and_trim(args, input_path)) {
|
||||
@ -283,26 +284,32 @@ static void infrared_cli_process_decode(Cli* cli, string_t args) {
|
||||
break;
|
||||
}
|
||||
args_read_probably_quoted_string_and_trim(args, output_path);
|
||||
if(!flipper_format_buffered_file_open_existing(input_file, string_get_cstr(input_path))) {
|
||||
printf("Failed to open file for reading: \"%s\"\r\n", string_get_cstr(input_path));
|
||||
if(!flipper_format_buffered_file_open_existing(
|
||||
input_file, furi_string_get_cstr(input_path))) {
|
||||
printf(
|
||||
"Failed to open file for reading: \"%s\"\r\n", furi_string_get_cstr(input_path));
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_header(input_file, header, &version) ||
|
||||
(!string_start_with_str_p(header, "IR")) || version != 1) {
|
||||
printf("Invalid or corrupted input file: \"%s\"\r\n", string_get_cstr(input_path));
|
||||
(!furi_string_start_with_str(header, "IR")) || version != 1) {
|
||||
printf(
|
||||
"Invalid or corrupted input file: \"%s\"\r\n", furi_string_get_cstr(input_path));
|
||||
break;
|
||||
}
|
||||
if(!string_empty_p(output_path)) {
|
||||
printf("Writing output to file: \"%s\"\r\n", string_get_cstr(output_path));
|
||||
if(!furi_string_empty(output_path)) {
|
||||
printf("Writing output to file: \"%s\"\r\n", furi_string_get_cstr(output_path));
|
||||
output_file = flipper_format_file_alloc(storage);
|
||||
}
|
||||
if(output_file &&
|
||||
!flipper_format_file_open_always(output_file, string_get_cstr(output_path))) {
|
||||
printf("Failed to open file for writing: \"%s\"\r\n", string_get_cstr(output_path));
|
||||
!flipper_format_file_open_always(output_file, furi_string_get_cstr(output_path))) {
|
||||
printf(
|
||||
"Failed to open file for writing: \"%s\"\r\n", furi_string_get_cstr(output_path));
|
||||
break;
|
||||
}
|
||||
if(output_file && !flipper_format_write_header(output_file, header, version)) {
|
||||
printf("Failed to write to the output file: \"%s\"\r\n", string_get_cstr(output_path));
|
||||
printf(
|
||||
"Failed to write to the output file: \"%s\"\r\n",
|
||||
furi_string_get_cstr(output_path));
|
||||
break;
|
||||
}
|
||||
if(!infrared_cli_decode_file(input_file, output_file)) {
|
||||
@ -311,31 +318,31 @@ static void infrared_cli_process_decode(Cli* cli, string_t args) {
|
||||
printf("File successfully decoded.\r\n");
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp);
|
||||
string_clear(header);
|
||||
string_clear(input_path);
|
||||
string_clear(output_path);
|
||||
furi_string_free(tmp);
|
||||
furi_string_free(header);
|
||||
furi_string_free(input_path);
|
||||
furi_string_free(output_path);
|
||||
|
||||
flipper_format_free(input_file);
|
||||
if(output_file) flipper_format_free(output_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void infrared_cli_start_ir(Cli* cli, string_t args, void* context) {
|
||||
static void infrared_cli_start_ir(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
if(furi_hal_infrared_is_busy()) {
|
||||
printf("INFRARED is busy. Exiting.");
|
||||
return;
|
||||
}
|
||||
|
||||
string_t command;
|
||||
string_init(command);
|
||||
FuriString* command;
|
||||
command = furi_string_alloc();
|
||||
args_read_string_and_trim(args, command);
|
||||
|
||||
size_t i = 0;
|
||||
for(; i < COUNT_OF(infrared_cli_commands); ++i) {
|
||||
size_t cmd_len = strlen(infrared_cli_commands[i].cmd);
|
||||
if(!strncmp(string_get_cstr(command), infrared_cli_commands[i].cmd, cmd_len)) {
|
||||
if(!strncmp(furi_string_get_cstr(command), infrared_cli_commands[i].cmd, cmd_len)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -346,7 +353,7 @@ static void infrared_cli_start_ir(Cli* cli, string_t args, void* context) {
|
||||
infrared_cli_print_usage();
|
||||
}
|
||||
|
||||
string_clear(command);
|
||||
furi_string_free(command);
|
||||
}
|
||||
void infrared_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
|
@ -96,7 +96,7 @@ struct Infrared {
|
||||
Loading* loading;
|
||||
InfraredProgressView* progress;
|
||||
|
||||
string_t file_path;
|
||||
FuriString* file_path;
|
||||
char text_store[INFRARED_TEXT_STORE_NUM][INFRARED_TEXT_STORE_SIZE + 1];
|
||||
InfraredAppState app_state;
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <m-string.h>
|
||||
#include <m-array.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <storage/storage.h>
|
||||
@ -15,8 +14,8 @@ ARRAY_DEF(InfraredButtonArray, InfraredRemoteButton*, M_PTR_OPLIST);
|
||||
|
||||
struct InfraredRemote {
|
||||
InfraredButtonArray_t buttons;
|
||||
string_t name;
|
||||
string_t path;
|
||||
FuriString* name;
|
||||
FuriString* path;
|
||||
};
|
||||
|
||||
static void infrared_remote_clear_buttons(InfraredRemote* remote) {
|
||||
@ -31,39 +30,39 @@ static void infrared_remote_clear_buttons(InfraredRemote* remote) {
|
||||
InfraredRemote* infrared_remote_alloc() {
|
||||
InfraredRemote* remote = malloc(sizeof(InfraredRemote));
|
||||
InfraredButtonArray_init(remote->buttons);
|
||||
string_init(remote->name);
|
||||
string_init(remote->path);
|
||||
remote->name = furi_string_alloc();
|
||||
remote->path = furi_string_alloc();
|
||||
return remote;
|
||||
}
|
||||
|
||||
void infrared_remote_free(InfraredRemote* remote) {
|
||||
infrared_remote_clear_buttons(remote);
|
||||
InfraredButtonArray_clear(remote->buttons);
|
||||
string_clear(remote->path);
|
||||
string_clear(remote->name);
|
||||
furi_string_free(remote->path);
|
||||
furi_string_free(remote->name);
|
||||
free(remote);
|
||||
}
|
||||
|
||||
void infrared_remote_reset(InfraredRemote* remote) {
|
||||
infrared_remote_clear_buttons(remote);
|
||||
string_reset(remote->name);
|
||||
string_reset(remote->path);
|
||||
furi_string_reset(remote->name);
|
||||
furi_string_reset(remote->path);
|
||||
}
|
||||
|
||||
void infrared_remote_set_name(InfraredRemote* remote, const char* name) {
|
||||
string_set_str(remote->name, name);
|
||||
furi_string_set(remote->name, name);
|
||||
}
|
||||
|
||||
const char* infrared_remote_get_name(InfraredRemote* remote) {
|
||||
return string_get_cstr(remote->name);
|
||||
return furi_string_get_cstr(remote->name);
|
||||
}
|
||||
|
||||
void infrared_remote_set_path(InfraredRemote* remote, const char* path) {
|
||||
string_set_str(remote->path, path);
|
||||
furi_string_set(remote->path, path);
|
||||
}
|
||||
|
||||
const char* infrared_remote_get_path(InfraredRemote* remote) {
|
||||
return string_get_cstr(remote->path);
|
||||
return furi_string_get_cstr(remote->path);
|
||||
}
|
||||
|
||||
size_t infrared_remote_get_button_count(InfraredRemote* remote) {
|
||||
@ -112,7 +111,7 @@ bool infrared_remote_delete_button(InfraredRemote* remote, size_t index) {
|
||||
bool infrared_remote_store(InfraredRemote* remote) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
const char* path = string_get_cstr(remote->path);
|
||||
const char* path = furi_string_get_cstr(remote->path);
|
||||
|
||||
FURI_LOG_I(TAG, "store file: \'%s\'", path);
|
||||
|
||||
@ -138,33 +137,33 @@ bool infrared_remote_store(InfraredRemote* remote) {
|
||||
return success;
|
||||
}
|
||||
|
||||
bool infrared_remote_load(InfraredRemote* remote, string_t path) {
|
||||
bool infrared_remote_load(InfraredRemote* remote, FuriString* path) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
|
||||
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
|
||||
FURI_LOG_I(TAG, "load file: \'%s\'", string_get_cstr(path));
|
||||
bool success = flipper_format_buffered_file_open_existing(ff, string_get_cstr(path));
|
||||
FURI_LOG_I(TAG, "load file: \'%s\'", furi_string_get_cstr(path));
|
||||
bool success = flipper_format_buffered_file_open_existing(ff, furi_string_get_cstr(path));
|
||||
|
||||
if(success) {
|
||||
uint32_t version;
|
||||
success = flipper_format_read_header(ff, buf, &version) &&
|
||||
!string_cmp_str(buf, "IR signals file") && (version == 1);
|
||||
!furi_string_cmp(buf, "IR signals file") && (version == 1);
|
||||
}
|
||||
|
||||
if(success) {
|
||||
path_extract_filename(path, buf, true);
|
||||
infrared_remote_clear_buttons(remote);
|
||||
infrared_remote_set_name(remote, string_get_cstr(buf));
|
||||
infrared_remote_set_path(remote, string_get_cstr(path));
|
||||
infrared_remote_set_name(remote, furi_string_get_cstr(buf));
|
||||
infrared_remote_set_path(remote, furi_string_get_cstr(path));
|
||||
|
||||
for(bool can_read = true; can_read;) {
|
||||
InfraredRemoteButton* button = infrared_remote_button_alloc();
|
||||
can_read = infrared_signal_read(infrared_remote_button_get_signal(button), ff, buf);
|
||||
if(can_read) {
|
||||
infrared_remote_button_set_name(button, string_get_cstr(buf));
|
||||
infrared_remote_button_set_name(button, furi_string_get_cstr(buf));
|
||||
InfraredButtonArray_push_back(remote->buttons, button);
|
||||
} else {
|
||||
infrared_remote_button_free(button);
|
||||
@ -172,7 +171,7 @@ bool infrared_remote_load(InfraredRemote* remote, string_t path) {
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return success;
|
||||
@ -181,7 +180,7 @@ bool infrared_remote_load(InfraredRemote* remote, string_t path) {
|
||||
bool infrared_remote_remove(InfraredRemote* remote) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FS_Error status = storage_common_remove(storage, string_get_cstr(remote->path));
|
||||
FS_Error status = storage_common_remove(storage, furi_string_get_cstr(remote->path));
|
||||
infrared_remote_reset(remote);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
@ -25,5 +25,5 @@ bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name,
|
||||
bool infrared_remote_delete_button(InfraredRemote* remote, size_t index);
|
||||
|
||||
bool infrared_remote_store(InfraredRemote* remote);
|
||||
bool infrared_remote_load(InfraredRemote* remote, string_t path);
|
||||
bool infrared_remote_load(InfraredRemote* remote, FuriString* path);
|
||||
bool infrared_remote_remove(InfraredRemote* remote);
|
||||
|
@ -1,32 +1,31 @@
|
||||
#include "infrared_remote_button.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <m-string.h>
|
||||
|
||||
struct InfraredRemoteButton {
|
||||
string_t name;
|
||||
FuriString* name;
|
||||
InfraredSignal* signal;
|
||||
};
|
||||
|
||||
InfraredRemoteButton* infrared_remote_button_alloc() {
|
||||
InfraredRemoteButton* button = malloc(sizeof(InfraredRemoteButton));
|
||||
string_init(button->name);
|
||||
button->name = furi_string_alloc();
|
||||
button->signal = infrared_signal_alloc();
|
||||
return button;
|
||||
}
|
||||
|
||||
void infrared_remote_button_free(InfraredRemoteButton* button) {
|
||||
string_clear(button->name);
|
||||
furi_string_free(button->name);
|
||||
infrared_signal_free(button->signal);
|
||||
free(button);
|
||||
}
|
||||
|
||||
void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name) {
|
||||
string_set_str(button->name, name);
|
||||
furi_string_set(button->name, name);
|
||||
}
|
||||
|
||||
const char* infrared_remote_button_get_name(InfraredRemoteButton* button) {
|
||||
return string_get_cstr(button->name);
|
||||
return furi_string_get_cstr(button->name);
|
||||
}
|
||||
|
||||
void infrared_remote_button_set_signal(InfraredRemoteButton* button, InfraredSignal* signal) {
|
||||
|
@ -100,15 +100,15 @@ static inline bool infrared_signal_save_raw(InfraredRawSignal* raw, FlipperForma
|
||||
}
|
||||
|
||||
static inline bool infrared_signal_read_message(InfraredSignal* signal, FlipperFormat* ff) {
|
||||
string_t buf;
|
||||
string_init(buf);
|
||||
FuriString* buf;
|
||||
buf = furi_string_alloc();
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!flipper_format_read_string(ff, "protocol", buf)) break;
|
||||
|
||||
InfraredMessage message;
|
||||
message.protocol = infrared_get_protocol_by_name(string_get_cstr(buf));
|
||||
message.protocol = infrared_get_protocol_by_name(furi_string_get_cstr(buf));
|
||||
|
||||
success = flipper_format_read_hex(ff, "address", (uint8_t*)&message.address, 4) &&
|
||||
flipper_format_read_hex(ff, "command", (uint8_t*)&message.command, 4) &&
|
||||
@ -119,7 +119,7 @@ static inline bool infrared_signal_read_message(InfraredSignal* signal, FlipperF
|
||||
infrared_signal_set_message(signal, &message);
|
||||
} while(0);
|
||||
|
||||
string_clear(buf);
|
||||
furi_string_free(buf);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -147,22 +147,22 @@ static inline bool infrared_signal_read_raw(InfraredSignal* signal, FlipperForma
|
||||
}
|
||||
|
||||
static bool infrared_signal_read_body(InfraredSignal* signal, FlipperFormat* ff) {
|
||||
string_t tmp;
|
||||
string_init(tmp);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!flipper_format_read_string(ff, "type", tmp)) break;
|
||||
if(string_equal_p(tmp, "raw")) {
|
||||
if(furi_string_equal(tmp, "raw")) {
|
||||
success = infrared_signal_read_raw(signal, ff);
|
||||
} else if(string_equal_p(tmp, "parsed")) {
|
||||
} else if(furi_string_equal(tmp, "parsed")) {
|
||||
success = infrared_signal_read_message(signal, ff);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unknown signal type");
|
||||
}
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp);
|
||||
furi_string_free(tmp);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -246,34 +246,33 @@ bool infrared_signal_save(InfraredSignal* signal, FlipperFormat* ff, const char*
|
||||
}
|
||||
}
|
||||
|
||||
bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, string_t name) {
|
||||
string_t tmp;
|
||||
string_init(tmp);
|
||||
bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, FuriString* name) {
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!flipper_format_read_string(ff, "name", tmp)) break;
|
||||
string_set(name, tmp);
|
||||
furi_string_set(name, tmp);
|
||||
if(!infrared_signal_read_body(signal, ff)) break;
|
||||
success = true;
|
||||
} while(0);
|
||||
|
||||
string_clear(tmp);
|
||||
furi_string_free(tmp);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool infrared_signal_search_and_read(
|
||||
InfraredSignal* signal,
|
||||
FlipperFormat* ff,
|
||||
const string_t name) {
|
||||
const FuriString* name) {
|
||||
bool success = false;
|
||||
string_t tmp;
|
||||
string_init(tmp);
|
||||
FuriString* tmp = furi_string_alloc();
|
||||
|
||||
do {
|
||||
bool is_name_found = false;
|
||||
while(flipper_format_read_string(ff, "name", tmp)) {
|
||||
is_name_found = string_equal_p(name, tmp);
|
||||
is_name_found = furi_string_equal(name, tmp);
|
||||
if(is_name_found) break;
|
||||
}
|
||||
if(!is_name_found) break;
|
||||
@ -281,7 +280,7 @@ bool infrared_signal_search_and_read(
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp);
|
||||
furi_string_free(tmp);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,10 @@ void infrared_signal_set_message(InfraredSignal* signal, const InfraredMessage*
|
||||
InfraredMessage* infrared_signal_get_message(InfraredSignal* signal);
|
||||
|
||||
bool infrared_signal_save(InfraredSignal* signal, FlipperFormat* ff, const char* name);
|
||||
bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, string_t name);
|
||||
bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, FuriString* name);
|
||||
bool infrared_signal_search_and_read(
|
||||
InfraredSignal* signal,
|
||||
FlipperFormat* ff,
|
||||
const string_t name);
|
||||
const FuriString* name);
|
||||
|
||||
void infrared_signal_transmit(InfraredSignal* signal);
|
||||
|
@ -29,20 +29,20 @@ void infrared_scene_edit_rename_on_enter(void* context) {
|
||||
enter_name_length = INFRARED_MAX_REMOTE_NAME_LENGTH;
|
||||
strncpy(infrared->text_store[0], infrared_remote_get_name(remote), enter_name_length);
|
||||
|
||||
string_t folder_path;
|
||||
string_init(folder_path);
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
if(string_end_with_str_p(infrared->file_path, INFRARED_APP_EXTENSION)) {
|
||||
path_extract_dirname(string_get_cstr(infrared->file_path), folder_path);
|
||||
if(furi_string_end_with(infrared->file_path, INFRARED_APP_EXTENSION)) {
|
||||
path_extract_dirname(furi_string_get_cstr(infrared->file_path), folder_path);
|
||||
}
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
string_get_cstr(folder_path),
|
||||
furi_string_get_cstr(folder_path),
|
||||
INFRARED_APP_EXTENSION,
|
||||
infrared_remote_get_name(remote));
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
string_clear(folder_path);
|
||||
furi_string_free(folder_path);
|
||||
} else {
|
||||
furi_assert(0);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
bool result = false;
|
||||
const char* arg = rpc_system_app_get_data(infrared->rpc_ctx);
|
||||
if(arg && (state == InfraredRpcStateIdle)) {
|
||||
string_set_str(infrared->file_path, arg);
|
||||
furi_string_set(infrared->file_path, arg);
|
||||
result = infrared_remote_load(infrared->remote, infrared->file_path);
|
||||
if(result) {
|
||||
scene_manager_set_scene_state(
|
||||
|
@ -66,7 +66,7 @@ bool infrared_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneLearn);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexSavedRemotes) {
|
||||
string_set_str(infrared->file_path, INFRARED_APP_FOLDER);
|
||||
furi_string_set(infrared->file_path, INFRARED_APP_FOLDER);
|
||||
scene_manager_next_scene(scene_manager, InfraredSceneRemoteList);
|
||||
consumed = true;
|
||||
} else if(submenu_index == SubmenuIndexDebug) {
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "gui/canvas.h"
|
||||
#include "gui/view.h"
|
||||
#include "input/input.h"
|
||||
#include "m-string.h"
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
#include "infrared_progress_view.h"
|
||||
|
@ -36,9 +36,9 @@ static LfRfid* lfrfid_alloc() {
|
||||
lfrfid->storage = furi_record_open(RECORD_STORAGE);
|
||||
lfrfid->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
string_init(lfrfid->file_name);
|
||||
string_init(lfrfid->raw_file_name);
|
||||
string_init_set_str(lfrfid->file_path, LFRFID_APP_FOLDER);
|
||||
lfrfid->file_name = furi_string_alloc();
|
||||
lfrfid->raw_file_name = furi_string_alloc();
|
||||
lfrfid->file_path = furi_string_alloc_set(LFRFID_APP_FOLDER);
|
||||
|
||||
lfrfid->dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
|
||||
@ -104,9 +104,9 @@ static LfRfid* lfrfid_alloc() {
|
||||
static void lfrfid_free(LfRfid* lfrfid) {
|
||||
furi_assert(lfrfid);
|
||||
|
||||
string_clear(lfrfid->raw_file_name);
|
||||
string_clear(lfrfid->file_name);
|
||||
string_clear(lfrfid->file_path);
|
||||
furi_string_free(lfrfid->raw_file_name);
|
||||
furi_string_free(lfrfid->file_name);
|
||||
furi_string_free(lfrfid->file_path);
|
||||
protocol_dict_free(lfrfid->dict);
|
||||
|
||||
lfrfid_worker_free(lfrfid->lfworker);
|
||||
@ -183,7 +183,7 @@ int32_t lfrfid_app(void* p) {
|
||||
app->view_dispatcher, app->gui, ViewDispatcherTypeDesktop);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneRpc);
|
||||
} else {
|
||||
string_set_str(app->file_path, args);
|
||||
furi_string_set(app->file_path, args);
|
||||
lfrfid_load_key_data(app, app->file_path, true);
|
||||
view_dispatcher_attach_to_gui(
|
||||
app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
@ -210,13 +210,13 @@ bool lfrfid_save_key(LfRfid* app) {
|
||||
|
||||
lfrfid_make_app_folder(app);
|
||||
|
||||
if(string_end_with_str_p(app->file_path, LFRFID_APP_EXTENSION)) {
|
||||
size_t filename_start = string_search_rchar(app->file_path, '/');
|
||||
string_left(app->file_path, filename_start);
|
||||
if(furi_string_end_with(app->file_path, LFRFID_APP_EXTENSION)) {
|
||||
size_t filename_start = furi_string_search_rchar(app->file_path, '/');
|
||||
furi_string_left(app->file_path, filename_start);
|
||||
}
|
||||
|
||||
string_cat_printf(
|
||||
app->file_path, "/%s%s", string_get_cstr(app->file_name), LFRFID_APP_EXTENSION);
|
||||
furi_string_cat_printf(
|
||||
app->file_path, "/%s%s", furi_string_get_cstr(app->file_name), LFRFID_APP_EXTENSION);
|
||||
|
||||
result = lfrfid_save_key_data(app, app->file_path);
|
||||
return result;
|
||||
@ -242,14 +242,14 @@ bool lfrfid_load_key_from_file_select(LfRfid* app) {
|
||||
bool lfrfid_delete_key(LfRfid* app) {
|
||||
furi_assert(app);
|
||||
|
||||
return storage_simply_remove(app->storage, string_get_cstr(app->file_path));
|
||||
return storage_simply_remove(app->storage, furi_string_get_cstr(app->file_path));
|
||||
}
|
||||
|
||||
bool lfrfid_load_key_data(LfRfid* app, string_t path, bool show_dialog) {
|
||||
bool lfrfid_load_key_data(LfRfid* app, FuriString* path, bool show_dialog) {
|
||||
bool result = false;
|
||||
|
||||
do {
|
||||
app->protocol_id = lfrfid_dict_file_load(app->dict, string_get_cstr(path));
|
||||
app->protocol_id = lfrfid_dict_file_load(app->dict, furi_string_get_cstr(path));
|
||||
if(app->protocol_id == PROTOCOL_NO) break;
|
||||
|
||||
path_extract_filename(path, app->file_name, true);
|
||||
@ -263,8 +263,8 @@ bool lfrfid_load_key_data(LfRfid* app, string_t path, bool show_dialog) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool lfrfid_save_key_data(LfRfid* app, string_t path) {
|
||||
bool result = lfrfid_dict_file_save(app->dict, app->protocol_id, string_get_cstr(path));
|
||||
bool lfrfid_save_key_data(LfRfid* app, FuriString* path) {
|
||||
bool result = lfrfid_dict_file_save(app->dict, app->protocol_id, furi_string_get_cstr(path));
|
||||
|
||||
if(!result) {
|
||||
dialog_message_show_storage_error(app->dialogs, "Cannot save\nkey file");
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <lfrfid/lfrfid_raw_file.h>
|
||||
#include <toolbox/pulse_protocols/pulse_glue.h>
|
||||
|
||||
static void lfrfid_cli(Cli* cli, string_t args, void* context);
|
||||
static void lfrfid_cli(Cli* cli, FuriString* args, void* context);
|
||||
|
||||
// app cli function
|
||||
void lfrfid_on_system_start() {
|
||||
@ -46,27 +46,28 @@ static void lfrfid_cli_read_callback(LFRFIDWorkerReadResult result, ProtocolId p
|
||||
furi_event_flag_set(context->event, 1 << result);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_read(Cli* cli, string_t args) {
|
||||
string_t type_string;
|
||||
string_init(type_string);
|
||||
static void lfrfid_cli_read(Cli* cli, FuriString* args) {
|
||||
FuriString* type_string;
|
||||
type_string = furi_string_alloc();
|
||||
LFRFIDWorkerReadType type = LFRFIDWorkerReadTypeAuto;
|
||||
|
||||
if(args_read_string_and_trim(args, type_string)) {
|
||||
if(string_cmp_str(type_string, "normal") == 0 || string_cmp_str(type_string, "ask") == 0) {
|
||||
if(furi_string_cmp_str(type_string, "normal") == 0 ||
|
||||
furi_string_cmp_str(type_string, "ask") == 0) {
|
||||
// ask
|
||||
type = LFRFIDWorkerReadTypeASKOnly;
|
||||
} else if(
|
||||
string_cmp_str(type_string, "indala") == 0 ||
|
||||
string_cmp_str(type_string, "psk") == 0) {
|
||||
furi_string_cmp_str(type_string, "indala") == 0 ||
|
||||
furi_string_cmp_str(type_string, "psk") == 0) {
|
||||
// psk
|
||||
type = LFRFIDWorkerReadTypePSKOnly;
|
||||
} else {
|
||||
lfrfid_cli_print_usage();
|
||||
string_clear(type_string);
|
||||
furi_string_free(type_string);
|
||||
return;
|
||||
}
|
||||
}
|
||||
string_clear(type_string);
|
||||
furi_string_free(type_string);
|
||||
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
LFRFIDWorker* worker = lfrfid_worker_alloc(dict);
|
||||
@ -111,13 +112,13 @@ static void lfrfid_cli_read(Cli* cli, string_t args) {
|
||||
printf("\r\n");
|
||||
free(data);
|
||||
|
||||
string_t info;
|
||||
string_init(info);
|
||||
FuriString* info;
|
||||
info = furi_string_alloc();
|
||||
protocol_dict_render_data(dict, info, context.protocol);
|
||||
if(!string_empty_p(info)) {
|
||||
printf("%s\r\n", string_get_cstr(info));
|
||||
if(!furi_string_empty(info)) {
|
||||
printf("%s\r\n", furi_string_get_cstr(info));
|
||||
}
|
||||
string_clear(info);
|
||||
furi_string_free(info);
|
||||
}
|
||||
|
||||
printf("Reading stopped\r\n");
|
||||
@ -126,11 +127,11 @@ static void lfrfid_cli_read(Cli* cli, string_t args) {
|
||||
furi_event_flag_free(context.event);
|
||||
}
|
||||
|
||||
static bool lfrfid_cli_parse_args(string_t args, ProtocolDict* dict, ProtocolId* protocol) {
|
||||
static bool lfrfid_cli_parse_args(FuriString* args, ProtocolDict* dict, ProtocolId* protocol) {
|
||||
bool result = false;
|
||||
string_t protocol_name, data_text;
|
||||
string_init(protocol_name);
|
||||
string_init(data_text);
|
||||
FuriString *protocol_name, *data_text;
|
||||
protocol_name = furi_string_alloc();
|
||||
data_text = furi_string_alloc();
|
||||
size_t data_size = protocol_dict_get_max_data_size(dict);
|
||||
uint8_t* data = malloc(data_size);
|
||||
|
||||
@ -143,12 +144,12 @@ static bool lfrfid_cli_parse_args(string_t args, ProtocolDict* dict, ProtocolId*
|
||||
}
|
||||
|
||||
// check protocol arg
|
||||
*protocol = protocol_dict_get_protocol_by_name(dict, string_get_cstr(protocol_name));
|
||||
*protocol = protocol_dict_get_protocol_by_name(dict, furi_string_get_cstr(protocol_name));
|
||||
if(*protocol == PROTOCOL_NO) {
|
||||
printf(
|
||||
"Unknown protocol: %s\r\n"
|
||||
"Available protocols:\r\n",
|
||||
string_get_cstr(protocol_name));
|
||||
furi_string_get_cstr(protocol_name));
|
||||
|
||||
for(ProtocolId i = 0; i < LFRFIDProtocolMax; i++) {
|
||||
printf(
|
||||
@ -177,8 +178,8 @@ static bool lfrfid_cli_parse_args(string_t args, ProtocolDict* dict, ProtocolId*
|
||||
} while(false);
|
||||
|
||||
free(data);
|
||||
string_clear(protocol_name);
|
||||
string_clear(data_text);
|
||||
furi_string_free(protocol_name);
|
||||
furi_string_free(data_text);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ static void lfrfid_cli_write_callback(LFRFIDWorkerWriteResult result, void* ctx)
|
||||
furi_event_flag_set(events, 1 << result);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_write(Cli* cli, string_t args) {
|
||||
static void lfrfid_cli_write(Cli* cli, FuriString* args) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
ProtocolId protocol;
|
||||
|
||||
@ -235,7 +236,7 @@ static void lfrfid_cli_write(Cli* cli, string_t args) {
|
||||
furi_event_flag_free(event);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_emulate(Cli* cli, string_t args) {
|
||||
static void lfrfid_cli_emulate(Cli* cli, FuriString* args) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
ProtocolId protocol;
|
||||
|
||||
@ -261,11 +262,11 @@ static void lfrfid_cli_emulate(Cli* cli, string_t args) {
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_raw_analyze(Cli* cli, string_t args) {
|
||||
static void lfrfid_cli_raw_analyze(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
string_t filepath, info_string;
|
||||
string_init(filepath);
|
||||
string_init(info_string);
|
||||
FuriString *filepath, *info_string;
|
||||
filepath = furi_string_alloc();
|
||||
info_string = furi_string_alloc();
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
LFRFIDRawFile* file = lfrfid_raw_file_alloc(storage);
|
||||
|
||||
@ -278,7 +279,7 @@ static void lfrfid_cli_raw_analyze(Cli* cli, string_t args) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!lfrfid_raw_file_open_read(file, string_get_cstr(filepath))) {
|
||||
if(!lfrfid_raw_file_open_read(file, furi_string_get_cstr(filepath))) {
|
||||
printf("Failed to open file\r\n");
|
||||
break;
|
||||
}
|
||||
@ -308,10 +309,10 @@ static void lfrfid_cli_raw_analyze(Cli* cli, string_t args) {
|
||||
warn = true;
|
||||
}
|
||||
|
||||
string_printf(info_string, "[%ld %ld]", pulse, duration);
|
||||
printf("%-16s", string_get_cstr(info_string));
|
||||
string_printf(info_string, "[%ld %ld]", pulse, duration - pulse);
|
||||
printf("%-16s", string_get_cstr(info_string));
|
||||
furi_string_printf(info_string, "[%ld %ld]", pulse, duration);
|
||||
printf("%-16s", furi_string_get_cstr(info_string));
|
||||
furi_string_printf(info_string, "[%ld %ld]", pulse, duration - pulse);
|
||||
printf("%-16s", furi_string_get_cstr(info_string));
|
||||
|
||||
if(warn) {
|
||||
printf(" <<----");
|
||||
@ -366,7 +367,7 @@ static void lfrfid_cli_raw_analyze(Cli* cli, string_t args) {
|
||||
printf("]\r\n");
|
||||
|
||||
protocol_dict_render_data(dict, info_string, total_protocol);
|
||||
printf("%s\r\n", string_get_cstr(info_string));
|
||||
printf("%s\r\n", furi_string_get_cstr(info_string));
|
||||
|
||||
free(data);
|
||||
} else {
|
||||
@ -376,8 +377,8 @@ static void lfrfid_cli_raw_analyze(Cli* cli, string_t args) {
|
||||
protocol_dict_free(dict);
|
||||
} while(false);
|
||||
|
||||
string_clear(filepath);
|
||||
string_clear(info_string);
|
||||
furi_string_free(filepath);
|
||||
furi_string_free(info_string);
|
||||
lfrfid_raw_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
@ -388,23 +389,23 @@ static void lfrfid_cli_raw_read_callback(LFRFIDWorkerReadRawResult result, void*
|
||||
furi_event_flag_set(event, 1 << result);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_raw_read(Cli* cli, string_t args) {
|
||||
static void lfrfid_cli_raw_read(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
|
||||
string_t filepath, type_string;
|
||||
string_init(filepath);
|
||||
string_init(type_string);
|
||||
FuriString *filepath, *type_string;
|
||||
filepath = furi_string_alloc();
|
||||
type_string = furi_string_alloc();
|
||||
LFRFIDWorkerReadType type = LFRFIDWorkerReadTypeAuto;
|
||||
|
||||
do {
|
||||
if(args_read_string_and_trim(args, type_string)) {
|
||||
if(string_cmp_str(type_string, "normal") == 0 ||
|
||||
string_cmp_str(type_string, "ask") == 0) {
|
||||
if(furi_string_cmp_str(type_string, "normal") == 0 ||
|
||||
furi_string_cmp_str(type_string, "ask") == 0) {
|
||||
// ask
|
||||
type = LFRFIDWorkerReadTypeASKOnly;
|
||||
} else if(
|
||||
string_cmp_str(type_string, "indala") == 0 ||
|
||||
string_cmp_str(type_string, "psk") == 0) {
|
||||
furi_string_cmp_str(type_string, "indala") == 0 ||
|
||||
furi_string_cmp_str(type_string, "psk") == 0) {
|
||||
// psk
|
||||
type = LFRFIDWorkerReadTypePSKOnly;
|
||||
} else {
|
||||
@ -430,7 +431,7 @@ static void lfrfid_cli_raw_read(Cli* cli, string_t args) {
|
||||
(1 << LFRFIDWorkerReadRawOverrun);
|
||||
|
||||
lfrfid_worker_read_raw_start(
|
||||
worker, string_get_cstr(filepath), type, lfrfid_cli_raw_read_callback, event);
|
||||
worker, furi_string_get_cstr(filepath), type, lfrfid_cli_raw_read_callback, event);
|
||||
while(true) {
|
||||
uint32_t flags = furi_event_flag_wait(event, available_flags, FuriFlagWaitAny, 100);
|
||||
|
||||
@ -465,8 +466,8 @@ static void lfrfid_cli_raw_read(Cli* cli, string_t args) {
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(filepath);
|
||||
string_clear(type_string);
|
||||
furi_string_free(filepath);
|
||||
furi_string_free(type_string);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_raw_emulate_callback(LFRFIDWorkerEmulateRawResult result, void* context) {
|
||||
@ -475,11 +476,11 @@ static void lfrfid_cli_raw_emulate_callback(LFRFIDWorkerEmulateRawResult result,
|
||||
furi_event_flag_set(event, 1 << result);
|
||||
}
|
||||
|
||||
static void lfrfid_cli_raw_emulate(Cli* cli, string_t args) {
|
||||
static void lfrfid_cli_raw_emulate(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
|
||||
string_t filepath;
|
||||
string_init(filepath);
|
||||
FuriString* filepath;
|
||||
filepath = furi_string_alloc();
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
do {
|
||||
@ -488,8 +489,8 @@ static void lfrfid_cli_raw_emulate(Cli* cli, string_t args) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!storage_file_exists(storage, string_get_cstr(filepath))) {
|
||||
printf("File not found: \"%s\"\r\n", string_get_cstr(filepath));
|
||||
if(!storage_file_exists(storage, furi_string_get_cstr(filepath))) {
|
||||
printf("File not found: \"%s\"\r\n", furi_string_get_cstr(filepath));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -505,7 +506,7 @@ static void lfrfid_cli_raw_emulate(Cli* cli, string_t args) {
|
||||
(1 << LFRFIDWorkerEmulateRawOverrun);
|
||||
|
||||
lfrfid_worker_emulate_raw_start(
|
||||
worker, string_get_cstr(filepath), lfrfid_cli_raw_emulate_callback, event);
|
||||
worker, furi_string_get_cstr(filepath), lfrfid_cli_raw_emulate_callback, event);
|
||||
while(true) {
|
||||
uint32_t flags = furi_event_flag_wait(event, available_flags, FuriFlagWaitAny, 100);
|
||||
|
||||
@ -541,35 +542,35 @@ static void lfrfid_cli_raw_emulate(Cli* cli, string_t args) {
|
||||
} while(false);
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
string_clear(filepath);
|
||||
furi_string_free(filepath);
|
||||
}
|
||||
|
||||
static void lfrfid_cli(Cli* cli, string_t args, void* context) {
|
||||
static void lfrfid_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
FuriString* cmd;
|
||||
cmd = furi_string_alloc();
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
lfrfid_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "read") == 0) {
|
||||
lfrfid_cli_read(cli, args);
|
||||
} else if(string_cmp_str(cmd, "write") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "write") == 0) {
|
||||
lfrfid_cli_write(cli, args);
|
||||
} else if(string_cmp_str(cmd, "emulate") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "emulate") == 0) {
|
||||
lfrfid_cli_emulate(cli, args);
|
||||
} else if(string_cmp_str(cmd, "raw_read") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "raw_read") == 0) {
|
||||
lfrfid_cli_raw_read(cli, args);
|
||||
} else if(string_cmp_str(cmd, "raw_emulate") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "raw_emulate") == 0) {
|
||||
lfrfid_cli_raw_emulate(cli, args);
|
||||
} else if(string_cmp_str(cmd, "raw_analyze") == 0) {
|
||||
} else if(furi_string_cmp_str(cmd, "raw_analyze") == 0) {
|
||||
lfrfid_cli_raw_analyze(cli, args);
|
||||
} else {
|
||||
lfrfid_cli_print_usage();
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
@ -86,9 +84,9 @@ struct LfRfid {
|
||||
Widget* widget;
|
||||
|
||||
char text_store[LFRFID_TEXT_STORE_SIZE + 1];
|
||||
string_t file_path;
|
||||
string_t file_name;
|
||||
string_t raw_file_name;
|
||||
FuriString* file_path;
|
||||
FuriString* file_name;
|
||||
FuriString* raw_file_name;
|
||||
|
||||
ProtocolDict* dict;
|
||||
ProtocolId protocol_id;
|
||||
@ -128,9 +126,9 @@ bool lfrfid_load_key_from_file_select(LfRfid* app);
|
||||
|
||||
bool lfrfid_delete_key(LfRfid* app);
|
||||
|
||||
bool lfrfid_load_key_data(LfRfid* app, string_t path, bool show_dialog);
|
||||
bool lfrfid_load_key_data(LfRfid* app, FuriString* path, bool show_dialog);
|
||||
|
||||
bool lfrfid_save_key_data(LfRfid* app, string_t path);
|
||||
bool lfrfid_save_key_data(LfRfid* app, FuriString* path);
|
||||
|
||||
void lfrfid_make_app_folder(LfRfid* app);
|
||||
|
||||
|
@ -4,31 +4,31 @@ void lfrfid_scene_delete_confirm_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
Widget* widget = app->widget;
|
||||
|
||||
string_t tmp_string;
|
||||
string_init(tmp_string);
|
||||
FuriString* tmp_string;
|
||||
tmp_string = furi_string_alloc();
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", lfrfid_widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", lfrfid_widget_callback, app);
|
||||
|
||||
string_printf(tmp_string, "Delete %s?", string_get_cstr(app->file_name));
|
||||
furi_string_printf(tmp_string, "Delete %s?", furi_string_get_cstr(app->file_name));
|
||||
widget_add_string_element(
|
||||
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, string_get_cstr(tmp_string));
|
||||
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp_string));
|
||||
|
||||
string_reset(tmp_string);
|
||||
furi_string_reset(tmp_string);
|
||||
size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
protocol_dict_get_data(app->dict, app->protocol_id, data, size);
|
||||
for(uint8_t i = 0; i < MIN(size, (size_t)8); i++) {
|
||||
if(i != 0) {
|
||||
string_cat_printf(tmp_string, " ");
|
||||
furi_string_cat_printf(tmp_string, " ");
|
||||
}
|
||||
|
||||
string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
furi_string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
}
|
||||
free(data);
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 64, 19, AlignCenter, AlignTop, FontSecondary, string_get_cstr(tmp_string));
|
||||
widget, 64, 19, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp_string));
|
||||
widget_add_string_element(
|
||||
widget,
|
||||
64,
|
||||
@ -39,7 +39,7 @@ void lfrfid_scene_delete_confirm_on_enter(void* context) {
|
||||
protocol_dict_get_name(app->dict, app->protocol_id));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
|
||||
string_clear(tmp_string);
|
||||
furi_string_free(tmp_string);
|
||||
}
|
||||
|
||||
bool lfrfid_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -8,8 +8,8 @@ void lfrfid_scene_emulate_on_enter(void* context) {
|
||||
DOLPHIN_DEED(DolphinDeedRfidEmulate);
|
||||
|
||||
popup_set_header(popup, "Emulating", 89, 30, AlignCenter, AlignTop);
|
||||
if(!string_empty_p(app->file_name)) {
|
||||
popup_set_text(popup, string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
|
||||
if(!furi_string_empty(app->file_name)) {
|
||||
popup_set_text(popup, furi_string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
|
||||
} else {
|
||||
popup_set_text(
|
||||
popup,
|
||||
|
@ -42,7 +42,7 @@ void lfrfid_scene_extra_actions_on_enter(void* context) {
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, LfRfidSceneExtraActions));
|
||||
|
||||
// clear key
|
||||
string_reset(app->file_name);
|
||||
furi_string_reset(app->file_name);
|
||||
app->protocol_id = PROTOCOL_NO;
|
||||
app->read_type = LFRFIDWorkerReadTypeAuto;
|
||||
|
||||
|
@ -4,8 +4,8 @@ void lfrfid_scene_raw_info_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
Widget* widget = app->widget;
|
||||
|
||||
// string_t tmp_string;
|
||||
// string_init(tmp_string);
|
||||
// FuriString* tmp_string;
|
||||
// tmp_string = furi_string_alloc();
|
||||
|
||||
bool sd_exist = storage_sd_status(app->storage) == FSE_OK;
|
||||
if(!sd_exist) {
|
||||
|
@ -4,9 +4,9 @@ void lfrfid_scene_raw_name_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
TextInput* text_input = app->text_input;
|
||||
|
||||
const char* key_name = string_get_cstr(app->raw_file_name);
|
||||
const char* key_name = furi_string_get_cstr(app->raw_file_name);
|
||||
|
||||
bool key_name_is_empty = string_empty_p(app->file_name);
|
||||
bool key_name_is_empty = furi_string_empty(app->file_name);
|
||||
if(key_name_is_empty) {
|
||||
lfrfid_text_store_set(app, "RfidRecord");
|
||||
} else {
|
||||
@ -38,7 +38,7 @@ bool lfrfid_scene_raw_name_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == LfRfidEventNext) {
|
||||
consumed = true;
|
||||
string_set_str(app->raw_file_name, app->text_store);
|
||||
furi_string_set(app->raw_file_name, app->text_store);
|
||||
scene_manager_next_scene(scene_manager, LfRfidSceneRawInfo);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#define RAW_READ_TIME 5000
|
||||
|
||||
typedef struct {
|
||||
string_t string_file_name;
|
||||
FuriString* string_file_name;
|
||||
FuriTimer* timer;
|
||||
bool is_psk;
|
||||
bool error;
|
||||
@ -31,7 +31,7 @@ void lfrfid_scene_raw_read_on_enter(void* context) {
|
||||
|
||||
LfRfidReadRawState* state = malloc(sizeof(LfRfidReadRawState));
|
||||
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneRawRead, (uint32_t)state);
|
||||
string_init(state->string_file_name);
|
||||
state->string_file_name = furi_string_alloc();
|
||||
|
||||
popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
|
||||
@ -40,16 +40,16 @@ void lfrfid_scene_raw_read_on_enter(void* context) {
|
||||
|
||||
state->timer = furi_timer_alloc(timer_callback, FuriTimerTypeOnce, app);
|
||||
furi_timer_start(state->timer, RAW_READ_TIME);
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
state->string_file_name,
|
||||
"%s/%s%s",
|
||||
LFRFID_SD_FOLDER,
|
||||
string_get_cstr(app->raw_file_name),
|
||||
furi_string_get_cstr(app->raw_file_name),
|
||||
LFRFID_APP_RAW_ASK_EXTENSION);
|
||||
popup_set_header(popup, "Reading\nRAW RFID\nASK", 89, 30, AlignCenter, AlignTop);
|
||||
lfrfid_worker_read_raw_start(
|
||||
app->lfworker,
|
||||
string_get_cstr(state->string_file_name),
|
||||
furi_string_get_cstr(state->string_file_name),
|
||||
LFRFIDWorkerReadTypeASKOnly,
|
||||
lfrfid_read_callback,
|
||||
app);
|
||||
@ -88,15 +88,15 @@ bool lfrfid_scene_raw_read_on_event(void* context, SceneManagerEvent event) {
|
||||
popup, "Reading\nRAW RFID\nPSK", 89, 30, AlignCenter, AlignTop);
|
||||
notification_message(app->notifications, &sequence_blink_start_yellow);
|
||||
lfrfid_worker_stop(app->lfworker);
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
state->string_file_name,
|
||||
"%s/%s%s",
|
||||
LFRFID_SD_FOLDER,
|
||||
string_get_cstr(app->raw_file_name),
|
||||
furi_string_get_cstr(app->raw_file_name),
|
||||
LFRFID_APP_RAW_PSK_EXTENSION);
|
||||
lfrfid_worker_read_raw_start(
|
||||
app->lfworker,
|
||||
string_get_cstr(state->string_file_name),
|
||||
furi_string_get_cstr(state->string_file_name),
|
||||
LFRFIDWorkerReadTypePSKOnly,
|
||||
lfrfid_read_callback,
|
||||
app);
|
||||
@ -121,6 +121,6 @@ void lfrfid_scene_raw_read_on_exit(void* context) {
|
||||
lfrfid_worker_stop_thread(app->lfworker);
|
||||
furi_timer_free(state->timer);
|
||||
|
||||
string_clear(state->string_file_name);
|
||||
furi_string_free(state->string_file_name);
|
||||
free(state);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ bool lfrfid_scene_read_on_event(void* context, SceneManagerEvent event) {
|
||||
app->protocol_id = app->protocol_id_next;
|
||||
DOLPHIN_DEED(DolphinDeedRfidReadSuccess);
|
||||
notification_message(app->notifications, &sequence_success);
|
||||
string_reset(app->file_name);
|
||||
furi_string_reset(app->file_name);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneReadSuccess);
|
||||
consumed = true;
|
||||
} else if(event.event == LfRfidEventReadStartPSK) {
|
||||
|
@ -38,7 +38,7 @@ bool lfrfid_scene_read_key_menu_on_event(void* context, SceneManagerEvent event)
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneWrite);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSave) {
|
||||
string_reset(app->file_name);
|
||||
furi_string_reset(app->file_name);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveName);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexEmulate) {
|
||||
|
@ -4,51 +4,51 @@ void lfrfid_scene_read_success_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
Widget* widget = app->widget;
|
||||
|
||||
string_t tmp_string;
|
||||
string_init(tmp_string);
|
||||
FuriString* tmp_string;
|
||||
tmp_string = furi_string_alloc();
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Retry", lfrfid_widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "More", lfrfid_widget_callback, app);
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
tmp_string,
|
||||
"%s[%s]",
|
||||
protocol_dict_get_name(app->dict, app->protocol_id),
|
||||
protocol_dict_get_manufacturer(app->dict, app->protocol_id));
|
||||
|
||||
widget_add_string_element(
|
||||
widget, 0, 2, AlignLeft, AlignTop, FontPrimary, string_get_cstr(tmp_string));
|
||||
widget, 0, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_string));
|
||||
|
||||
string_reset(tmp_string);
|
||||
furi_string_reset(tmp_string);
|
||||
size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
|
||||
uint8_t* data = (uint8_t*)malloc(size);
|
||||
protocol_dict_get_data(app->dict, app->protocol_id, data, size);
|
||||
for(uint8_t i = 0; i < size; i++) {
|
||||
if(i >= 9) {
|
||||
string_cat_printf(tmp_string, "..");
|
||||
furi_string_cat_printf(tmp_string, "..");
|
||||
break;
|
||||
} else {
|
||||
if(i != 0) {
|
||||
string_cat_printf(tmp_string, " ");
|
||||
furi_string_cat_printf(tmp_string, " ");
|
||||
}
|
||||
string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
furi_string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
|
||||
string_t render_data;
|
||||
string_init(render_data);
|
||||
FuriString* render_data;
|
||||
render_data = furi_string_alloc();
|
||||
protocol_dict_render_brief_data(app->dict, render_data, app->protocol_id);
|
||||
string_cat_printf(tmp_string, "\r\n%s", string_get_cstr(render_data));
|
||||
string_clear(render_data);
|
||||
furi_string_cat_printf(tmp_string, "\r\n%s", furi_string_get_cstr(render_data));
|
||||
furi_string_free(render_data);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 0, 16, AlignLeft, AlignTop, FontSecondary, string_get_cstr(tmp_string));
|
||||
widget, 0, 16, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_string));
|
||||
|
||||
notification_message_block(app->notifications, &sequence_set_green_255);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
|
||||
string_clear(tmp_string);
|
||||
furi_string_free(tmp_string);
|
||||
}
|
||||
|
||||
bool lfrfid_scene_read_success_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -34,13 +34,14 @@ bool lfrfid_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
const char* arg = rpc_system_app_get_data(app->rpc_ctx);
|
||||
bool result = false;
|
||||
if(arg && (app->rpc_state == LfRfidRpcStateIdle)) {
|
||||
string_set_str(app->file_path, arg);
|
||||
furi_string_set(app->file_path, arg);
|
||||
if(lfrfid_load_key_data(app, app->file_path, false)) {
|
||||
lfrfid_worker_start_thread(app->lfworker);
|
||||
lfrfid_worker_emulate_start(app->lfworker, (LFRFIDProtocol)app->protocol_id);
|
||||
app->rpc_state = LfRfidRpcStateEmulating;
|
||||
|
||||
lfrfid_text_store_set(app, "emulating\n%s", string_get_cstr(app->file_name));
|
||||
lfrfid_text_store_set(
|
||||
app, "emulating\n%s", furi_string_get_cstr(app->file_name));
|
||||
popup_set_text(popup, app->text_store, 89, 44, AlignCenter, AlignTop);
|
||||
|
||||
notification_message(app->notifications, &sequence_blink_start_magenta);
|
||||
|
@ -1,21 +1,20 @@
|
||||
#include "m-string.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include "../lfrfid_i.h"
|
||||
|
||||
void lfrfid_scene_save_name_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
TextInput* text_input = app->text_input;
|
||||
string_t folder_path;
|
||||
string_init(folder_path);
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
bool key_name_is_empty = string_empty_p(app->file_name);
|
||||
bool key_name_is_empty = furi_string_empty(app->file_name);
|
||||
if(key_name_is_empty) {
|
||||
string_set_str(app->file_path, LFRFID_APP_FOLDER);
|
||||
furi_string_set(app->file_path, LFRFID_APP_FOLDER);
|
||||
set_random_name(app->text_store, LFRFID_TEXT_STORE_SIZE);
|
||||
string_set_str(folder_path, LFRFID_APP_FOLDER);
|
||||
furi_string_set(folder_path, LFRFID_APP_FOLDER);
|
||||
} else {
|
||||
lfrfid_text_store_set(app, "%s", string_get_cstr(app->file_name));
|
||||
path_extract_dirname(string_get_cstr(app->file_path), folder_path);
|
||||
lfrfid_text_store_set(app, "%s", furi_string_get_cstr(app->file_name));
|
||||
path_extract_dirname(furi_string_get_cstr(app->file_path), folder_path);
|
||||
}
|
||||
|
||||
text_input_set_header_text(text_input, "Name the card");
|
||||
@ -27,13 +26,15 @@ void lfrfid_scene_save_name_on_enter(void* context) {
|
||||
LFRFID_KEY_NAME_SIZE,
|
||||
key_name_is_empty);
|
||||
|
||||
FURI_LOG_I("", "%s %s", string_get_cstr(folder_path), app->text_store);
|
||||
FURI_LOG_I("", "%s %s", furi_string_get_cstr(folder_path), app->text_store);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
string_get_cstr(folder_path), LFRFID_APP_EXTENSION, string_get_cstr(app->file_name));
|
||||
furi_string_get_cstr(folder_path),
|
||||
LFRFID_APP_EXTENSION,
|
||||
furi_string_get_cstr(app->file_name));
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
string_clear(folder_path);
|
||||
furi_string_free(folder_path);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewTextInput);
|
||||
}
|
||||
@ -46,11 +47,11 @@ bool lfrfid_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == LfRfidEventNext) {
|
||||
consumed = true;
|
||||
if(!string_empty_p(app->file_name)) {
|
||||
if(!furi_string_empty(app->file_name)) {
|
||||
lfrfid_delete_key(app);
|
||||
}
|
||||
|
||||
string_set_str(app->file_name, app->text_store);
|
||||
furi_string_set(app->file_name, app->text_store);
|
||||
|
||||
if(lfrfid_save_key(app)) {
|
||||
scene_manager_next_scene(scene_manager, LfRfidSceneSaveSuccess);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../lfrfid_i.h"
|
||||
|
||||
typedef struct {
|
||||
string_t menu_item_name[LFRFIDProtocolMax];
|
||||
FuriString* menu_item_name[LFRFIDProtocolMax];
|
||||
uint32_t line_sel;
|
||||
} SaveTypeCtx;
|
||||
|
||||
@ -20,18 +20,17 @@ void lfrfid_scene_save_type_on_enter(void* context) {
|
||||
if(strcmp(
|
||||
protocol_dict_get_manufacturer(app->dict, i),
|
||||
protocol_dict_get_name(app->dict, i)) != 0) {
|
||||
string_init_printf(
|
||||
state->menu_item_name[i],
|
||||
state->menu_item_name[i] = furi_string_alloc_printf(
|
||||
"%s %s",
|
||||
protocol_dict_get_manufacturer(app->dict, i),
|
||||
protocol_dict_get_name(app->dict, i));
|
||||
} else {
|
||||
string_init_printf(
|
||||
state->menu_item_name[i], "%s", protocol_dict_get_name(app->dict, i));
|
||||
state->menu_item_name[i] =
|
||||
furi_string_alloc_printf("%s", protocol_dict_get_name(app->dict, i));
|
||||
}
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
string_get_cstr(state->menu_item_name[i]),
|
||||
furi_string_get_cstr(state->menu_item_name[i]),
|
||||
i,
|
||||
lfrfid_scene_save_type_submenu_callback,
|
||||
app);
|
||||
@ -43,7 +42,7 @@ void lfrfid_scene_save_type_on_enter(void* context) {
|
||||
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneSaveType, (uint32_t)state);
|
||||
|
||||
// clear key name
|
||||
string_reset(app->file_name);
|
||||
furi_string_reset(app->file_name);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewSubmenu);
|
||||
}
|
||||
@ -75,7 +74,7 @@ void lfrfid_scene_save_type_on_exit(void* context) {
|
||||
submenu_reset(app->submenu);
|
||||
|
||||
for(uint8_t i = 0; i < LFRFIDProtocolMax; i++) {
|
||||
string_clear(state->menu_item_name[i]);
|
||||
furi_string_free(state->menu_item_name[i]);
|
||||
}
|
||||
|
||||
uint32_t line_sel = state->line_sel;
|
||||
|
@ -4,13 +4,13 @@ void lfrfid_scene_saved_info_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
Widget* widget = app->widget;
|
||||
|
||||
string_t tmp_string;
|
||||
string_init(tmp_string);
|
||||
FuriString* tmp_string;
|
||||
tmp_string = furi_string_alloc();
|
||||
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
tmp_string,
|
||||
"%s [%s]\r\n",
|
||||
string_get_cstr(app->file_name),
|
||||
furi_string_get_cstr(app->file_name),
|
||||
protocol_dict_get_name(app->dict, app->protocol_id));
|
||||
|
||||
size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
|
||||
@ -18,24 +18,24 @@ void lfrfid_scene_saved_info_on_enter(void* context) {
|
||||
protocol_dict_get_data(app->dict, app->protocol_id, data, size);
|
||||
for(uint8_t i = 0; i < size; i++) {
|
||||
if(i != 0) {
|
||||
string_cat_printf(tmp_string, " ");
|
||||
furi_string_cat_printf(tmp_string, " ");
|
||||
}
|
||||
|
||||
string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
furi_string_cat_printf(tmp_string, "%02X", data[i]);
|
||||
}
|
||||
free(data);
|
||||
|
||||
string_t render_data;
|
||||
string_init(render_data);
|
||||
FuriString* render_data;
|
||||
render_data = furi_string_alloc();
|
||||
protocol_dict_render_data(app->dict, render_data, app->protocol_id);
|
||||
string_cat_printf(tmp_string, "\r\n%s", string_get_cstr(render_data));
|
||||
string_clear(render_data);
|
||||
furi_string_cat_printf(tmp_string, "\r\n%s", furi_string_get_cstr(render_data));
|
||||
furi_string_free(render_data);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
widget, 0, 1, AlignLeft, AlignTop, FontSecondary, string_get_cstr(tmp_string));
|
||||
widget, 0, 1, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_string));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
|
||||
string_clear(tmp_string);
|
||||
furi_string_free(tmp_string);
|
||||
}
|
||||
|
||||
bool lfrfid_scene_saved_info_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@ -33,7 +33,7 @@ void lfrfid_scene_start_on_enter(void* context) {
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, LfRfidSceneStart));
|
||||
|
||||
// clear key
|
||||
string_reset(app->file_name);
|
||||
furi_string_reset(app->file_name);
|
||||
app->protocol_id = PROTOCOL_NO;
|
||||
app->read_type = LFRFIDWorkerReadTypeAuto;
|
||||
|
||||
@ -49,7 +49,7 @@ bool lfrfid_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneRead);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
string_set_str(app->file_path, LFRFID_APP_FOLDER);
|
||||
furi_string_set(app->file_path, LFRFID_APP_FOLDER);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneSelectKey);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexAddManually) {
|
||||
|
@ -22,8 +22,8 @@ void lfrfid_scene_write_on_enter(void* context) {
|
||||
Popup* popup = app->popup;
|
||||
|
||||
popup_set_header(popup, "Writing", 89, 30, AlignCenter, AlignTop);
|
||||
if(!string_empty_p(app->file_name)) {
|
||||
popup_set_text(popup, string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
|
||||
if(!furi_string_empty(app->file_name)) {
|
||||
popup_set_text(popup, furi_string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
|
||||
} else {
|
||||
popup_set_text(
|
||||
popup,
|
||||
|
@ -7,12 +7,12 @@ static const uint32_t nfc_resources_file_version = 1;
|
||||
static bool nfc_emv_parser_search_data(
|
||||
Storage* storage,
|
||||
const char* file_name,
|
||||
string_t key,
|
||||
string_t data) {
|
||||
FuriString* key,
|
||||
FuriString* data) {
|
||||
bool parsed = false;
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
do {
|
||||
// Open file
|
||||
@ -20,14 +20,14 @@ static bool nfc_emv_parser_search_data(
|
||||
// Read file header and version
|
||||
uint32_t version = 0;
|
||||
if(!flipper_format_read_header(file, temp_str, &version)) break;
|
||||
if(string_cmp_str(temp_str, nfc_resources_header) ||
|
||||
if(furi_string_cmp_str(temp_str, nfc_resources_header) ||
|
||||
(version != nfc_resources_file_version))
|
||||
break;
|
||||
if(!flipper_format_read_string(file, string_get_cstr(key), data)) break;
|
||||
if(!flipper_format_read_string(file, furi_string_get_cstr(key), data)) break;
|
||||
parsed = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
flipper_format_free(file);
|
||||
return parsed;
|
||||
}
|
||||
@ -36,47 +36,47 @@ bool nfc_emv_parser_get_aid_name(
|
||||
Storage* storage,
|
||||
uint8_t* aid,
|
||||
uint8_t aid_len,
|
||||
string_t aid_name) {
|
||||
FuriString* aid_name) {
|
||||
furi_assert(storage);
|
||||
bool parsed = false;
|
||||
string_t key;
|
||||
string_init(key);
|
||||
FuriString* key;
|
||||
key = furi_string_alloc();
|
||||
for(uint8_t i = 0; i < aid_len; i++) {
|
||||
string_cat_printf(key, "%02X", aid[i]);
|
||||
furi_string_cat_printf(key, "%02X", aid[i]);
|
||||
}
|
||||
if(nfc_emv_parser_search_data(storage, EXT_PATH("nfc/assets/aid.nfc"), key, aid_name)) {
|
||||
parsed = true;
|
||||
}
|
||||
string_clear(key);
|
||||
furi_string_free(key);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
bool nfc_emv_parser_get_country_name(
|
||||
Storage* storage,
|
||||
uint16_t country_code,
|
||||
string_t country_name) {
|
||||
FuriString* country_name) {
|
||||
bool parsed = false;
|
||||
string_t key;
|
||||
string_init_printf(key, "%04X", country_code);
|
||||
FuriString* key;
|
||||
key = furi_string_alloc_printf("%04X", country_code);
|
||||
if(nfc_emv_parser_search_data(
|
||||
storage, EXT_PATH("nfc/assets/country_code.nfc"), key, country_name)) {
|
||||
parsed = true;
|
||||
}
|
||||
string_clear(key);
|
||||
furi_string_free(key);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
bool nfc_emv_parser_get_currency_name(
|
||||
Storage* storage,
|
||||
uint16_t currency_code,
|
||||
string_t currency_name) {
|
||||
FuriString* currency_name) {
|
||||
bool parsed = false;
|
||||
string_t key;
|
||||
string_init_printf(key, "%04X", currency_code);
|
||||
FuriString* key;
|
||||
key = furi_string_alloc_printf("%04X", currency_code);
|
||||
if(nfc_emv_parser_search_data(
|
||||
storage, EXT_PATH("nfc/assets/currency_code.nfc"), key, currency_name)) {
|
||||
parsed = true;
|
||||
}
|
||||
string_clear(key);
|
||||
furi_string_free(key);
|
||||
return parsed;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <m-string.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
/** Get EMV application name by number
|
||||
@ -16,7 +15,7 @@ bool nfc_emv_parser_get_aid_name(
|
||||
Storage* storage,
|
||||
uint8_t* aid,
|
||||
uint8_t aid_len,
|
||||
string_t aid_name);
|
||||
FuriString* aid_name);
|
||||
|
||||
/** Get country name by country code
|
||||
* @param storage Storage instance
|
||||
@ -27,7 +26,7 @@ bool nfc_emv_parser_get_aid_name(
|
||||
bool nfc_emv_parser_get_country_name(
|
||||
Storage* storage,
|
||||
uint16_t country_code,
|
||||
string_t country_name);
|
||||
FuriString* country_name);
|
||||
|
||||
/** Get currency name by currency code
|
||||
* @param storage Storage instance
|
||||
@ -38,4 +37,4 @@ bool nfc_emv_parser_get_country_name(
|
||||
bool nfc_emv_parser_get_currency_name(
|
||||
Storage* storage,
|
||||
uint16_t currency_code,
|
||||
string_t currency_name);
|
||||
FuriString* currency_name);
|
||||
|
@ -83,7 +83,7 @@ Nfc* nfc_alloc() {
|
||||
nfc->text_box = text_box_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->view_dispatcher, NfcViewTextBox, text_box_get_view(nfc->text_box));
|
||||
string_init(nfc->text_box_store);
|
||||
nfc->text_box_store = furi_string_alloc();
|
||||
|
||||
// Custom Widget
|
||||
nfc->widget = widget_alloc();
|
||||
@ -153,7 +153,7 @@ void nfc_free(Nfc* nfc) {
|
||||
// TextBox
|
||||
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
text_box_free(nfc->text_box);
|
||||
string_clear(nfc->text_box_store);
|
||||
furi_string_free(nfc->text_box_store);
|
||||
|
||||
// Custom Widget
|
||||
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
|
@ -17,7 +17,7 @@ static void nfc_cli_print_usage() {
|
||||
}
|
||||
}
|
||||
|
||||
static void nfc_cli_detect(Cli* cli, string_t args) {
|
||||
static void nfc_cli_detect(Cli* cli, FuriString* args) {
|
||||
UNUSED(args);
|
||||
// Check if nfc worker is not busy
|
||||
if(furi_hal_nfc_is_busy()) {
|
||||
@ -46,7 +46,7 @@ static void nfc_cli_detect(Cli* cli, string_t args) {
|
||||
furi_hal_nfc_sleep();
|
||||
}
|
||||
|
||||
static void nfc_cli_emulate(Cli* cli, string_t args) {
|
||||
static void nfc_cli_emulate(Cli* cli, FuriString* args) {
|
||||
UNUSED(args);
|
||||
// Check if nfc worker is not busy
|
||||
if(furi_hal_nfc_is_busy()) {
|
||||
@ -76,7 +76,7 @@ static void nfc_cli_emulate(Cli* cli, string_t args) {
|
||||
furi_hal_nfc_sleep();
|
||||
}
|
||||
|
||||
static void nfc_cli_field(Cli* cli, string_t args) {
|
||||
static void nfc_cli_field(Cli* cli, FuriString* args) {
|
||||
UNUSED(args);
|
||||
// Check if nfc worker is not busy
|
||||
if(furi_hal_nfc_is_busy()) {
|
||||
@ -98,27 +98,27 @@ static void nfc_cli_field(Cli* cli, string_t args) {
|
||||
furi_hal_nfc_sleep();
|
||||
}
|
||||
|
||||
static void nfc_cli(Cli* cli, string_t args, void* context) {
|
||||
static void nfc_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)) {
|
||||
nfc_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "detect") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "detect") == 0) {
|
||||
nfc_cli_detect(cli, args);
|
||||
break;
|
||||
}
|
||||
if(string_cmp_str(cmd, "emulate") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "emulate") == 0) {
|
||||
nfc_cli_emulate(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
if(string_cmp_str(cmd, "field") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "field") == 0) {
|
||||
nfc_cli_field(cli, args);
|
||||
break;
|
||||
}
|
||||
@ -127,7 +127,7 @@ static void nfc_cli(Cli* cli, string_t args, void* context) {
|
||||
nfc_cli_print_usage();
|
||||
} while(false);
|
||||
|
||||
string_clear(cmd);
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
void nfc_on_system_start() {
|
||||
|
@ -62,7 +62,7 @@ struct Nfc {
|
||||
FuriHalNfcDevData dev_edit_data;
|
||||
|
||||
char text_store[NFC_TEXT_STORE_SIZE + 1];
|
||||
string_t text_box_store;
|
||||
FuriString* text_box_store;
|
||||
uint8_t byte_input_store[6];
|
||||
MfClassicUserKeys_t mfc_key_strs; // Used in MFC key listing
|
||||
|
||||
|
@ -12,40 +12,40 @@ void nfc_scene_delete_on_enter(void* context) {
|
||||
FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data;
|
||||
|
||||
// Setup Custom Widget view
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
string_printf(temp_str, "\e#Delete %s?\e#", nfc->dev->dev_name);
|
||||
furi_string_printf(temp_str, "\e#Delete %s?\e#", nfc->dev->dev_name);
|
||||
widget_add_text_box_element(
|
||||
nfc->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, string_get_cstr(temp_str), false);
|
||||
nfc->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeLeft, "Cancel", nfc_scene_delete_widget_callback, nfc);
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
|
||||
|
||||
string_set_str(temp_str, "UID:");
|
||||
furi_string_set(temp_str, "UID:");
|
||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
}
|
||||
widget_add_string_element(
|
||||
nfc->widget, 64, 24, AlignCenter, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
nfc->widget, 64, 24, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
|
||||
NfcProtocol protocol = nfc->dev->dev_data.protocol;
|
||||
if(protocol == NfcDeviceProtocolEMV) {
|
||||
string_set_str(temp_str, "EMV bank card");
|
||||
furi_string_set(temp_str, "EMV bank card");
|
||||
} else if(protocol == NfcDeviceProtocolMifareUl) {
|
||||
string_set_str(temp_str, nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, true));
|
||||
furi_string_set(temp_str, nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, true));
|
||||
} else if(protocol == NfcDeviceProtocolMifareClassic) {
|
||||
string_set_str(temp_str, nfc_mf_classic_type(nfc->dev->dev_data.mf_classic_data.type));
|
||||
furi_string_set(temp_str, nfc_mf_classic_type(nfc->dev->dev_data.mf_classic_data.type));
|
||||
} else if(protocol == NfcDeviceProtocolMifareDesfire) {
|
||||
string_set_str(temp_str, "MIFARE DESFire");
|
||||
furi_string_set(temp_str, "MIFARE DESFire");
|
||||
} else {
|
||||
string_set_str(temp_str, "Unknown ISO tag");
|
||||
furi_string_set(temp_str, "Unknown ISO tag");
|
||||
}
|
||||
widget_add_string_element(
|
||||
nfc->widget, 64, 34, AlignCenter, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
nfc->widget, 64, 34, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
widget_add_string_element(nfc->widget, 64, 44, AlignCenter, AlignTop, FontSecondary, "NFC-A");
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
@ -12,49 +12,52 @@ void nfc_scene_device_info_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
||||
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
if(dev_data->protocol == NfcDeviceProtocolEMV) {
|
||||
EmvData* emv_data = &dev_data->emv_data;
|
||||
string_printf(temp_str, "\e#%s\n", emv_data->name);
|
||||
furi_string_printf(temp_str, "\e#%s\n", emv_data->name);
|
||||
for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
|
||||
string_cat_printf(temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
||||
furi_string_cat_printf(
|
||||
temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
||||
}
|
||||
string_strim(temp_str);
|
||||
furi_string_trim(temp_str);
|
||||
|
||||
// Add expiration date
|
||||
if(emv_data->exp_mon) {
|
||||
string_cat_printf(temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
||||
}
|
||||
// Parse currency code
|
||||
if((emv_data->currency_code)) {
|
||||
string_t currency_name;
|
||||
string_init(currency_name);
|
||||
FuriString* currency_name;
|
||||
currency_name = furi_string_alloc();
|
||||
if(nfc_emv_parser_get_currency_name(
|
||||
nfc->dev->storage, emv_data->currency_code, currency_name)) {
|
||||
string_cat_printf(temp_str, "\nCur: %s ", string_get_cstr(currency_name));
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nCur: %s ", furi_string_get_cstr(currency_name));
|
||||
}
|
||||
string_clear(currency_name);
|
||||
furi_string_free(currency_name);
|
||||
}
|
||||
// Parse country code
|
||||
if((emv_data->country_code)) {
|
||||
string_t country_name;
|
||||
string_init(country_name);
|
||||
FuriString* country_name;
|
||||
country_name = furi_string_alloc();
|
||||
if(nfc_emv_parser_get_country_name(
|
||||
nfc->dev->storage, emv_data->country_code, country_name)) {
|
||||
string_cat_printf(temp_str, "Reg: %s", string_get_cstr(country_name));
|
||||
furi_string_cat_printf(temp_str, "Reg: %s", furi_string_get_cstr(country_name));
|
||||
}
|
||||
string_clear(country_name);
|
||||
furi_string_free(country_name);
|
||||
}
|
||||
} else if(
|
||||
dev_data->protocol == NfcDeviceProtocolMifareClassic ||
|
||||
dev_data->protocol == NfcDeviceProtocolMifareUl) {
|
||||
string_set(temp_str, nfc->dev->dev_data.parsed_data);
|
||||
furi_string_set(temp_str, nfc->dev->dev_data.parsed_data);
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_device_info_widget_callback, nfc);
|
||||
|
@ -35,22 +35,22 @@ static void nfc_scene_emulate_uid_widget_config(Nfc* nfc, bool data_received) {
|
||||
FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
|
||||
Widget* widget = nfc->widget;
|
||||
widget_reset(widget);
|
||||
string_t info_str;
|
||||
string_init(info_str);
|
||||
FuriString* info_str;
|
||||
info_str = furi_string_alloc();
|
||||
|
||||
widget_add_icon_element(widget, 0, 3, &I_RFIDDolphinSend_97x61);
|
||||
widget_add_string_element(widget, 89, 32, AlignCenter, AlignTop, FontPrimary, "Emulating UID");
|
||||
if(strcmp(nfc->dev->dev_name, "")) {
|
||||
string_printf(info_str, "%s", nfc->dev->dev_name);
|
||||
furi_string_printf(info_str, "%s", nfc->dev->dev_name);
|
||||
} else {
|
||||
for(uint8_t i = 0; i < data->uid_len; i++) {
|
||||
string_cat_printf(info_str, "%02X ", data->uid[i]);
|
||||
furi_string_cat_printf(info_str, "%02X ", data->uid[i]);
|
||||
}
|
||||
}
|
||||
string_strim(info_str);
|
||||
furi_string_trim(info_str);
|
||||
widget_add_text_box_element(
|
||||
widget, 56, 43, 70, 21, AlignCenter, AlignTop, string_get_cstr(info_str), true);
|
||||
string_clear(info_str);
|
||||
widget, 56, 43, 70, 21, AlignCenter, AlignTop, furi_string_get_cstr(info_str), true);
|
||||
furi_string_free(info_str);
|
||||
if(data_received) {
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeCenter, "Log", nfc_scene_emulate_uid_widget_callback, nfc);
|
||||
@ -67,7 +67,7 @@ void nfc_scene_emulate_uid_on_enter(void* context) {
|
||||
TextBox* text_box = nfc->text_box;
|
||||
text_box_set_font(text_box, TextBoxFontHex);
|
||||
text_box_set_focus(text_box, TextBoxFocusEnd);
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
|
||||
// Set Widget state and view
|
||||
scene_manager_set_scene_state(
|
||||
@ -94,17 +94,17 @@ bool nfc_scene_emulate_uid_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventWorkerExit) {
|
||||
// Add data button to widget if data is received for the first time
|
||||
if(!string_size(nfc->text_box_store)) {
|
||||
if(!furi_string_size(nfc->text_box_store)) {
|
||||
nfc_scene_emulate_uid_widget_config(nfc, true);
|
||||
}
|
||||
// Update TextBox data
|
||||
if(string_size(nfc->text_box_store) < NFC_SCENE_EMULATE_UID_LOG_SIZE_MAX) {
|
||||
string_cat_printf(nfc->text_box_store, "R:");
|
||||
if(furi_string_size(nfc->text_box_store) < NFC_SCENE_EMULATE_UID_LOG_SIZE_MAX) {
|
||||
furi_string_cat_printf(nfc->text_box_store, "R:");
|
||||
for(uint16_t i = 0; i < reader_data->size; i++) {
|
||||
string_cat_printf(nfc->text_box_store, " %02X", reader_data->data[i]);
|
||||
furi_string_cat_printf(nfc->text_box_store, " %02X", reader_data->data[i]);
|
||||
}
|
||||
string_push_back(nfc->text_box_store, '\n');
|
||||
text_box_set_text(nfc->text_box, string_get_cstr(nfc->text_box_store));
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
text_box_set_text(nfc->text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
}
|
||||
memset(reader_data, 0, sizeof(NfcReaderRequestData));
|
||||
consumed = true;
|
||||
@ -140,7 +140,7 @@ void nfc_scene_emulate_uid_on_exit(void* context) {
|
||||
// Clear view
|
||||
widget_reset(nfc->widget);
|
||||
text_box_reset(nfc->text_box);
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
|
||||
nfc_blink_stop(nfc);
|
||||
}
|
||||
|
@ -23,42 +23,44 @@ void nfc_scene_emv_read_success_on_enter(void* context) {
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_emv_read_success_widget_callback, nfc);
|
||||
|
||||
string_t temp_str;
|
||||
string_init_printf(temp_str, "\e#%s\n", emv_data->name);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc_printf("\e#%s\n", emv_data->name);
|
||||
for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
|
||||
string_cat_printf(temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
||||
furi_string_cat_printf(
|
||||
temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
||||
}
|
||||
string_strim(temp_str);
|
||||
furi_string_trim(temp_str);
|
||||
|
||||
// Add expiration date
|
||||
if(emv_data->exp_mon) {
|
||||
string_cat_printf(temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
||||
}
|
||||
// Parse currency code
|
||||
if((emv_data->currency_code)) {
|
||||
string_t currency_name;
|
||||
string_init(currency_name);
|
||||
FuriString* currency_name;
|
||||
currency_name = furi_string_alloc();
|
||||
if(nfc_emv_parser_get_currency_name(
|
||||
nfc->dev->storage, emv_data->currency_code, currency_name)) {
|
||||
string_cat_printf(temp_str, "\nCur: %s ", string_get_cstr(currency_name));
|
||||
furi_string_cat_printf(temp_str, "\nCur: %s ", furi_string_get_cstr(currency_name));
|
||||
}
|
||||
string_clear(currency_name);
|
||||
furi_string_free(currency_name);
|
||||
}
|
||||
// Parse country code
|
||||
if((emv_data->country_code)) {
|
||||
string_t country_name;
|
||||
string_init(country_name);
|
||||
FuriString* country_name;
|
||||
country_name = furi_string_alloc();
|
||||
if(nfc_emv_parser_get_country_name(
|
||||
nfc->dev->storage, emv_data->country_code, country_name)) {
|
||||
string_cat_printf(temp_str, "Reg: %s", string_get_cstr(country_name));
|
||||
furi_string_cat_printf(temp_str, "Reg: %s", furi_string_get_cstr(country_name));
|
||||
}
|
||||
string_clear(country_name);
|
||||
furi_string_free(country_name);
|
||||
}
|
||||
|
||||
notification_message_block(nfc->notifications, &sequence_set_green_255);
|
||||
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
@ -16,15 +16,15 @@ void nfc_scene_generate_info_on_enter(void* context) {
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
|
||||
// Create info text
|
||||
string_t info_str;
|
||||
string_init_printf(
|
||||
info_str, "%s\n%s\nUID:", nfc->generator->name, nfc_get_dev_type(data->type));
|
||||
FuriString* info_str = furi_string_alloc_printf(
|
||||
"%s\n%s\nUID:", nfc->generator->name, nfc_get_dev_type(data->type));
|
||||
|
||||
// Append UID
|
||||
for(int i = 0; i < data->uid_len; ++i) {
|
||||
string_cat_printf(info_str, " %02X", data->uid[i]);
|
||||
furi_string_cat_printf(info_str, " %02X", data->uid[i]);
|
||||
}
|
||||
nfc_text_store_set(nfc, string_get_cstr(info_str));
|
||||
string_clear(info_str);
|
||||
nfc_text_store_set(nfc, furi_string_get_cstr(info_str));
|
||||
furi_string_free(info_str);
|
||||
|
||||
dialog_ex_set_text(dialog_ex, nfc->text_store, 0, 0, AlignLeft, AlignTop);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
|
@ -16,8 +16,8 @@ void nfc_scene_mf_classic_keys_delete_on_enter(void* context) {
|
||||
uint32_t key_index =
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicKeysDelete);
|
||||
// Setup Custom Widget view
|
||||
string_t key_str;
|
||||
string_init(key_str);
|
||||
FuriString* key_str;
|
||||
key_str = furi_string_alloc();
|
||||
|
||||
widget_add_string_element(
|
||||
nfc->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Delete this key?");
|
||||
@ -36,9 +36,15 @@ void nfc_scene_mf_classic_keys_delete_on_enter(void* context) {
|
||||
|
||||
mf_classic_dict_get_key_at_index_str(dict, key_str, key_index);
|
||||
widget_add_string_element(
|
||||
nfc->widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(key_str));
|
||||
nfc->widget,
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
FontSecondary,
|
||||
furi_string_get_cstr(key_str));
|
||||
|
||||
string_clear(key_str);
|
||||
furi_string_free(key_str);
|
||||
mf_classic_dict_free(dict);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
|
@ -19,19 +19,19 @@ void nfc_scene_mf_classic_keys_list_popup_callback(void* context) {
|
||||
void nfc_scene_mf_classic_keys_list_prepare(Nfc* nfc, MfClassicDict* dict) {
|
||||
Submenu* submenu = nfc->submenu;
|
||||
uint32_t index = 0;
|
||||
string_t temp_key;
|
||||
string_init(temp_key);
|
||||
FuriString* temp_key;
|
||||
temp_key = furi_string_alloc();
|
||||
|
||||
submenu_set_header(submenu, "Select key to delete:");
|
||||
while(mf_classic_dict_get_next_key_str(dict, temp_key)) {
|
||||
char* current_key = (char*)malloc(sizeof(char) * 13);
|
||||
strncpy(current_key, string_get_cstr(temp_key), 12);
|
||||
strncpy(current_key, furi_string_get_cstr(temp_key), 12);
|
||||
MfClassicUserKeys_push_back(nfc->mfc_key_strs, current_key);
|
||||
FURI_LOG_D("ListKeys", "Key %d: %s", index, current_key);
|
||||
submenu_add_item(
|
||||
submenu, current_key, index++, nfc_scene_mf_classic_keys_list_submenu_callback, nfc);
|
||||
}
|
||||
string_clear(temp_key);
|
||||
furi_string_free(temp_key);
|
||||
}
|
||||
|
||||
void nfc_scene_mf_classic_keys_list_on_enter(void* context) {
|
||||
|
@ -27,26 +27,26 @@ void nfc_scene_mf_classic_read_success_on_enter(void* context) {
|
||||
widget_add_button_element(
|
||||
widget, GuiButtonTypeRight, "More", nfc_scene_mf_classic_read_success_widget_callback, nfc);
|
||||
|
||||
string_t temp_str;
|
||||
if(string_size(nfc->dev->dev_data.parsed_data)) {
|
||||
string_init_set(temp_str, nfc->dev->dev_data.parsed_data);
|
||||
FuriString* temp_str;
|
||||
if(furi_string_size(nfc->dev->dev_data.parsed_data)) {
|
||||
temp_str = furi_string_alloc_set(nfc->dev->dev_data.parsed_data);
|
||||
} else {
|
||||
string_init_printf(temp_str, "\e#%s\n", nfc_mf_classic_type(mf_data->type));
|
||||
string_cat_printf(temp_str, "UID:");
|
||||
temp_str = furi_string_alloc_printf("\e#%s\n", nfc_mf_classic_type(mf_data->type));
|
||||
furi_string_cat_printf(temp_str, "UID:");
|
||||
for(size_t i = 0; i < dev_data->nfc_data.uid_len; i++) {
|
||||
string_cat_printf(temp_str, " %02X", dev_data->nfc_data.uid[i]);
|
||||
furi_string_cat_printf(temp_str, " %02X", dev_data->nfc_data.uid[i]);
|
||||
}
|
||||
uint8_t sectors_total = mf_classic_get_total_sectors_num(mf_data->type);
|
||||
uint8_t keys_total = sectors_total * 2;
|
||||
uint8_t keys_found = 0;
|
||||
uint8_t sectors_read = 0;
|
||||
mf_classic_get_read_sectors_and_keys(mf_data, §ors_read, &keys_found);
|
||||
string_cat_printf(temp_str, "\nKeys Found: %d/%d", keys_found, keys_total);
|
||||
string_cat_printf(temp_str, "\nSectors Read: %d/%d", sectors_read, sectors_total);
|
||||
furi_string_cat_printf(temp_str, "\nKeys Found: %d/%d", keys_found, keys_total);
|
||||
furi_string_cat_printf(temp_str, "\nSectors Read: %d/%d", sectors_read, sectors_total);
|
||||
}
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
notification_message_block(nfc->notifications, &sequence_set_green_255);
|
||||
|
||||
|
@ -84,7 +84,7 @@ bool nfc_scene_mf_desfire_app_on_event(void* context, SceneManagerEvent event) {
|
||||
} else {
|
||||
MifareDesfireApplication* app = nfc_scene_mf_desfire_app_get_app(nfc);
|
||||
TextBox* text_box = nfc->text_box;
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
if(event.event == SubmenuIndexAppInfo) {
|
||||
mf_df_cat_application_info(app, nfc->text_box_store);
|
||||
} else {
|
||||
@ -98,7 +98,7 @@ bool nfc_scene_mf_desfire_app_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
mf_df_cat_file(file, nfc->text_box_store);
|
||||
}
|
||||
text_box_set_text(text_box, string_get_cstr(nfc->text_box_store));
|
||||
text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfDesfireApp, state | 1);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
consumed = true;
|
||||
@ -120,6 +120,6 @@ void nfc_scene_mf_desfire_app_on_exit(void* context) {
|
||||
// Clear views
|
||||
popup_reset(nfc->popup);
|
||||
text_box_reset(nfc->text_box);
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ bool nfc_scene_mf_desfire_data_on_event(void* context, SceneManagerEvent event)
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
TextBox* text_box = nfc->text_box;
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
if(event.event == SubmenuIndexCardInfo) {
|
||||
mf_df_cat_card_info(data, nfc->text_box_store);
|
||||
text_box_set_text(text_box, string_get_cstr(nfc->text_box_store));
|
||||
text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager,
|
||||
@ -102,6 +102,6 @@ void nfc_scene_mf_desfire_data_on_exit(void* context) {
|
||||
|
||||
// Clear views
|
||||
text_box_reset(nfc->text_box);
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
||||
|
@ -20,20 +20,19 @@ void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
|
||||
Widget* widget = nfc->widget;
|
||||
|
||||
// Prepare string for data display
|
||||
string_t temp_str;
|
||||
string_init_printf(temp_str, "\e#MIFARE DESfire\n");
|
||||
string_cat_printf(temp_str, "UID:");
|
||||
FuriString* temp_str = furi_string_alloc_printf("\e#MIFARE DESfire\n");
|
||||
furi_string_cat_printf(temp_str, "UID:");
|
||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
}
|
||||
|
||||
uint32_t bytes_total = 1 << (data->version.sw_storage >> 1);
|
||||
uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0;
|
||||
string_cat_printf(temp_str, "\n%d", bytes_total);
|
||||
furi_string_cat_printf(temp_str, "\n%d", bytes_total);
|
||||
if(data->version.sw_storage & 1) {
|
||||
string_push_back(temp_str, '+');
|
||||
furi_string_push_back(temp_str, '+');
|
||||
}
|
||||
string_cat_printf(temp_str, " bytes, %d bytes free\n", bytes_free);
|
||||
furi_string_cat_printf(temp_str, " bytes, %d bytes free\n", bytes_free);
|
||||
|
||||
uint16_t n_apps = 0;
|
||||
uint16_t n_files = 0;
|
||||
@ -43,20 +42,20 @@ void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
|
||||
n_files++;
|
||||
}
|
||||
}
|
||||
string_cat_printf(temp_str, "%d Application", n_apps);
|
||||
furi_string_cat_printf(temp_str, "%d Application", n_apps);
|
||||
if(n_apps != 1) {
|
||||
string_push_back(temp_str, 's');
|
||||
furi_string_push_back(temp_str, 's');
|
||||
}
|
||||
string_cat_printf(temp_str, ", %d file", n_files);
|
||||
furi_string_cat_printf(temp_str, ", %d file", n_files);
|
||||
if(n_files != 1) {
|
||||
string_push_back(temp_str, 's');
|
||||
furi_string_push_back(temp_str, 's');
|
||||
}
|
||||
|
||||
notification_message_block(nfc->notifications, &sequence_set_green_255);
|
||||
|
||||
// Add text scroll element
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
// Add button elements
|
||||
widget_add_button_element(
|
||||
|
@ -8,11 +8,11 @@ void nfc_scene_mf_ultralight_data_on_enter(void* context) {
|
||||
text_box_set_font(text_box, TextBoxFontHex);
|
||||
for(uint16_t i = 0; i < data->data_size; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
string_push_back(nfc->text_box_store, '\n');
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
string_cat_printf(nfc->text_box_store, "%02X%02X ", data->data[i], data->data[i + 1]);
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data->data[i], data->data[i + 1]);
|
||||
}
|
||||
text_box_set_text(text_box, string_get_cstr(nfc->text_box_store));
|
||||
text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
}
|
||||
@ -28,5 +28,5 @@ void nfc_scene_mf_ultralight_data_on_exit(void* context) {
|
||||
|
||||
// Clean view
|
||||
text_box_reset(nfc->text_box);
|
||||
string_reset(nfc->text_box_store);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
}
|
@ -21,8 +21,8 @@ void nfc_scene_mf_ultralight_read_auth_result_on_enter(void* context) {
|
||||
MfUltralightData* mf_ul_data = &nfc->dev->dev_data.mf_ul_data;
|
||||
MfUltralightConfigPages* config_pages = mf_ultralight_get_config_pages(mf_ul_data);
|
||||
Widget* widget = nfc->widget;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
if((mf_ul_data->data_read == mf_ul_data->data_size) && (mf_ul_data->data_read > 0)) {
|
||||
widget_add_string_element(
|
||||
@ -31,14 +31,14 @@ void nfc_scene_mf_ultralight_read_auth_result_on_enter(void* context) {
|
||||
widget_add_string_element(
|
||||
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Not all pages unlocked!");
|
||||
}
|
||||
string_set_str(temp_str, "UID:");
|
||||
furi_string_set(temp_str, "UID:");
|
||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||
string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||
}
|
||||
widget_add_string_element(
|
||||
widget, 0, 17, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
widget, 0, 17, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
if(mf_ul_data->auth_success) {
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
temp_str,
|
||||
"Password: %02X %02X %02X %02X",
|
||||
config_pages->auth_data.pwd.raw[0],
|
||||
@ -46,19 +46,19 @@ void nfc_scene_mf_ultralight_read_auth_result_on_enter(void* context) {
|
||||
config_pages->auth_data.pwd.raw[2],
|
||||
config_pages->auth_data.pwd.raw[3]);
|
||||
widget_add_string_element(
|
||||
widget, 0, 28, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
string_printf(
|
||||
widget, 0, 28, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
furi_string_printf(
|
||||
temp_str,
|
||||
"PACK: %02X %02X",
|
||||
config_pages->auth_data.pack.raw[0],
|
||||
config_pages->auth_data.pack.raw[1]);
|
||||
widget_add_string_element(
|
||||
widget, 0, 39, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
widget, 0, 39, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
}
|
||||
string_printf(
|
||||
furi_string_printf(
|
||||
temp_str, "Pages Read: %d/%d", mf_ul_data->data_read / 4, mf_ul_data->data_size / 4);
|
||||
widget_add_string_element(
|
||||
widget, 0, 50, AlignLeft, AlignTop, FontSecondary, string_get_cstr(temp_str));
|
||||
widget, 0, 50, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
|
||||
widget_add_button_element(
|
||||
widget,
|
||||
GuiButtonTypeRight,
|
||||
@ -66,7 +66,7 @@ void nfc_scene_mf_ultralight_read_auth_result_on_enter(void* context) {
|
||||
nfc_scene_mf_ultralight_read_auth_result_widget_callback,
|
||||
nfc);
|
||||
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
||||
|
@ -33,23 +33,23 @@ void nfc_scene_mf_ultralight_read_success_on_enter(void* context) {
|
||||
nfc_scene_mf_ultralight_read_success_widget_callback,
|
||||
nfc);
|
||||
|
||||
string_t temp_str;
|
||||
if(string_size(nfc->dev->dev_data.parsed_data)) {
|
||||
string_init_set(temp_str, nfc->dev->dev_data.parsed_data);
|
||||
FuriString* temp_str;
|
||||
if(furi_string_size(nfc->dev->dev_data.parsed_data)) {
|
||||
temp_str = furi_string_alloc_set(nfc->dev->dev_data.parsed_data);
|
||||
} else {
|
||||
string_init_printf(temp_str, "\e#%s\n", nfc_mf_ul_type(mf_ul_data->type, true));
|
||||
string_cat_printf(temp_str, "UID:");
|
||||
temp_str = furi_string_alloc_printf("\e#%s\n", nfc_mf_ul_type(mf_ul_data->type, true));
|
||||
furi_string_cat_printf(temp_str, "UID:");
|
||||
for(size_t i = 0; i < data->uid_len; i++) {
|
||||
string_cat_printf(temp_str, " %02X", data->uid[i]);
|
||||
furi_string_cat_printf(temp_str, " %02X", data->uid[i]);
|
||||
}
|
||||
string_cat_printf(
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\nPages Read: %d/%d", mf_ul_data->data_read / 4, mf_ul_data->data_size / 4);
|
||||
if(mf_ul_data->data_read != mf_ul_data->data_size) {
|
||||
string_cat_printf(temp_str, "\nPassword-protected pages!");
|
||||
furi_string_cat_printf(temp_str, "\nPassword-protected pages!");
|
||||
}
|
||||
}
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
notification_message_block(nfc->notifications, &sequence_set_green_255);
|
||||
|
||||
|
@ -11,21 +11,21 @@ void nfc_scene_mfkey_nonces_info_callback(GuiButtonType result, InputType type,
|
||||
void nfc_scene_mfkey_nonces_info_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
|
||||
uint16_t nonces_saved = mfkey32_get_auth_sectors(temp_str);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 22, 128, 42, string_get_cstr(temp_str));
|
||||
string_printf(temp_str, "Nonces saved %d", nonces_saved);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 22, 128, 42, furi_string_get_cstr(temp_str));
|
||||
furi_string_printf(temp_str, "Nonces saved %d", nonces_saved);
|
||||
widget_add_string_element(
|
||||
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, string_get_cstr(temp_str));
|
||||
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(temp_str));
|
||||
widget_add_string_element(
|
||||
nfc->widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Authenticated sectors:");
|
||||
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "Next", nfc_scene_mfkey_nonces_info_callback, nfc);
|
||||
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user