[FL-2212] File validators and archive fixes #972

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-01-29 12:39:10 +03:00
committed by GitHub
parent 84410c83b5
commit 6264ee8c3b
24 changed files with 194 additions and 52 deletions

View File

@@ -35,9 +35,9 @@ void LfRfidAppSceneDeleteConfirm::on_enter(LfRfidApp* app, bool need_restore) {
string_printf(string_header, "Delete %s?", key.get_name());
line_1->set_text(
string_get_cstr(string_header), 64, 19, AlignCenter, AlignBottom, FontPrimary);
string_get_cstr(string_header), 64, 19, 128 - 2, AlignCenter, AlignBottom, FontPrimary);
line_2->set_text(
string_get_cstr(string_data), 64, 29, AlignCenter, AlignBottom, FontSecondary);
string_get_cstr(string_data), 64, 29, 0, AlignCenter, AlignBottom, FontSecondary);
switch(key.get_type()) {
case LfrfidKeyType::KeyEM4100:
@@ -52,12 +52,13 @@ void LfRfidAppSceneDeleteConfirm::on_enter(LfRfidApp* app, bool need_restore) {
break;
}
line_3->set_text(
string_get_cstr(string_decrypted), 64, 39, AlignCenter, AlignBottom, FontSecondary);
string_get_cstr(string_decrypted), 64, 39, 0, AlignCenter, AlignBottom, FontSecondary);
line_4->set_text(
lfrfid_key_get_type_string(key.get_type()),
64,
49,
0,
AlignCenter,
AlignBottom,
FontSecondary);

View File

@@ -36,9 +36,9 @@ void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool need_restore) {
switch(app->worker.key.get_type()) {
case LfrfidKeyType::KeyEM4100:
line_1_text->set_text("HEX:", 65, 23, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("Mod:", 65, 35, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("ID:", 65, 47, AlignRight, AlignBottom, FontSecondary);
line_1_text->set_text("HEX:", 65, 23, 0, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("Mod:", 65, 35, 0, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("ID:", 65, 47, 0, AlignRight, AlignBottom, FontSecondary);
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(string[0], "%02X", data[i]);
@@ -48,17 +48,17 @@ void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool need_restore) {
string_printf(string[2], "%03u,%05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
line_1_value->set_text(
string_get_cstr(string[0]), 68, 23, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[0]), 68, 23, 0, AlignLeft, AlignBottom, FontSecondary);
line_2_value->set_text(
string_get_cstr(string[1]), 68, 35, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[1]), 68, 35, 0, AlignLeft, AlignBottom, FontSecondary);
line_3_value->set_text(
string_get_cstr(string[2]), 68, 47, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[2]), 68, 47, 0, AlignLeft, AlignBottom, FontSecondary);
break;
case LfrfidKeyType::KeyH10301:
case LfrfidKeyType::KeyI40134:
line_1_text->set_text("HEX:", 65, 23, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("FC:", 65, 35, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("Card:", 65, 47, AlignRight, AlignBottom, FontSecondary);
line_1_text->set_text("HEX:", 65, 23, 0, AlignRight, AlignBottom, FontSecondary);
line_2_text->set_text("FC:", 65, 35, 0, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("Card:", 65, 47, 0, AlignRight, AlignBottom, FontSecondary);
for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
string_cat_printf(string[0], "%02X", data[i]);
@@ -68,11 +68,11 @@ void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool need_restore) {
string_printf(string[2], "%u", (uint16_t)((data[1] << 8) | (data[2])));
line_1_value->set_text(
string_get_cstr(string[0]), 68, 23, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[0]), 68, 23, 0, AlignLeft, AlignBottom, FontSecondary);
line_2_value->set_text(
string_get_cstr(string[1]), 68, 35, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[1]), 68, 35, 0, AlignLeft, AlignBottom, FontSecondary);
line_3_value->set_text(
string_get_cstr(string[2]), 68, 47, AlignLeft, AlignBottom, FontSecondary);
string_get_cstr(string[2]), 68, 47, 0, AlignLeft, AlignBottom, FontSecondary);
break;
}

View File

@@ -21,6 +21,10 @@ void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) {
app->worker.key.get_name_length(),
key_name_empty);
ValidatorIsFile* validator_is_file =
validator_is_file_alloc_init(app->app_folder, app->app_extension);
text_input->set_validator(validator_is_file_callback, validator_is_file);
app->view_controller.switch_to<TextInputVM>();
}
@@ -46,6 +50,11 @@ bool LfRfidAppSceneSaveName::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
}
void LfRfidAppSceneSaveName::on_exit(LfRfidApp* app) {
void* validator_context =
app->view_controller.get<TextInputVM>()->get_validator_callback_context();
app->view_controller.get<TextInputVM>()->set_validator(NULL, NULL);
validator_is_file_free((ValidatorIsFile*)validator_context);
app->view_controller.get<TextInputVM>()->clean();
}

View File

@@ -28,8 +28,9 @@ void LfRfidAppSceneSavedInfo::on_enter(LfRfidApp* app, bool need_restore) {
string_cat_printf(string_data, "%02X", data[i]);
}
line_1->set_text(key.get_name(), 64, 17, AlignCenter, AlignBottom, FontSecondary);
line_2->set_text(string_get_cstr(string_data), 64, 29, AlignCenter, AlignBottom, FontPrimary);
line_1->set_text(key.get_name(), 64, 17, 128 - 2, AlignCenter, AlignBottom, FontSecondary);
line_2->set_text(
string_get_cstr(string_data), 64, 29, 0, AlignCenter, AlignBottom, FontPrimary);
switch(key.get_type()) {
case LfrfidKeyType::KeyEM4100:
@@ -44,12 +45,13 @@ void LfRfidAppSceneSavedInfo::on_enter(LfRfidApp* app, bool need_restore) {
break;
}
line_3->set_text(
string_get_cstr(string_decrypted), 64, 39, AlignCenter, AlignBottom, FontSecondary);
string_get_cstr(string_decrypted), 64, 39, 0, AlignCenter, AlignBottom, FontSecondary);
line_4->set_text(
lfrfid_key_get_type_string(key.get_type()),
64,
49,
0,
AlignCenter,
AlignBottom,
FontSecondary);

View File

@@ -9,8 +9,17 @@ StringElement::~StringElement() {
void StringElement::draw(Canvas* canvas) {
if(text) {
string_t line;
string_init(line);
string_set_str(line, text);
canvas_set_font(canvas, font);
elements_multiline_text_aligned(canvas, x, y, horizontal, vertical, text);
if(fit_width != 0) {
elements_string_fit_width(canvas, line, fit_width);
}
elements_multiline_text_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(line));
string_clear(line);
}
}
@@ -22,6 +31,7 @@ void StringElement::set_text(
const char* _text,
uint8_t _x,
uint8_t _y,
uint8_t _fit_w,
Align _horizontal,
Align _vertical,
Font _font) {
@@ -29,8 +39,9 @@ void StringElement::set_text(
text = _text;
x = _x;
y = _y;
fit_width = _fit_w;
horizontal = _horizontal;
vertical = _vertical;
font = _font;
unlock_model(true);
}
}

View File

@@ -12,6 +12,7 @@ public:
const char* text = NULL,
uint8_t x = 0,
uint8_t y = 0,
uint8_t fit_width = 0,
Align horizontal = AlignLeft,
Align vertical = AlignTop,
Font font = FontPrimary);
@@ -20,6 +21,7 @@ private:
const char* text = NULL;
uint8_t x = 0;
uint8_t y = 0;
uint8_t fit_width = 0;
Align horizontal = AlignLeft;
Align vertical = AlignTop;
Font font = FontPrimary;