lambda the flash util menu add item code (#1993)

* lambda the flash util menu add code

* clean up
This commit is contained in:
not tre mann 2024-03-15 11:56:55 +08:00 committed by GitHub
parent f0614c882b
commit 181624daf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,7 +26,7 @@
namespace ui { namespace ui {
static const char16_t* firmware_folder = u"/FIRMWARE"; static const std::filesystem::path firmware_path = u"/FIRMWARE";
// Firmware image validation // Firmware image validation
static const char* hackrf_magic = "HACKRFFW"; static const char* hackrf_magic = "HACKRFFW";
@ -84,30 +84,29 @@ FlashUtilityView::FlashUtilityView(NavigationView& nav)
menu_view.set_parent_rect({0, 3 * 8, 240, 33 * 8}); menu_view.set_parent_rect({0, 3 * 8, 240, 33 * 8});
ensure_directory(firmware_folder); ensure_directory(firmware_path);
for (const auto& entry : std::filesystem::directory_iterator(firmware_folder, u"*.bin")) { auto add_firmware_items = [&](
auto filename = entry.path().filename(); const std::filesystem::path& folder_path,
auto path = entry.path().native(); const std::filesystem::path& wild,
ui::Color color) {
for (const auto& entry : std::filesystem::directory_iterator(folder_path, wild)) {
auto filename = entry.path().filename();
auto path = entry.path().native();
menu_view.add_item({filename.string().substr(0, max_filename_length), menu_view.add_item({filename.string().substr(0, max_filename_length),
ui::Color::red(), color,
&bitmap_icon_temperature, &bitmap_icon_temperature,
[this, path](KeyEvent) { [this, path](KeyEvent) {
this->firmware_selected(path); this->firmware_selected(path);
}}); }});
} }
for (const auto& entry : std::filesystem::directory_iterator(firmware_folder, u"*.tar")) { };
auto filename = entry.path().filename();
auto path = entry.path().native();
menu_view.add_item({filename.string().substr(0, max_filename_length), add_firmware_items(firmware_path, u"*.bin", ui::Color::red());
ui::Color::purple(), add_firmware_items(firmware_path, u"*.tar", ui::Color::purple());
&bitmap_icon_temperature,
[this, path](KeyEvent) { // add_firmware_items(user_firmware_folder,u"*.bin", ui::Color::purple());
this->firmware_selected(path);
}});
}
} }
void FlashUtilityView::firmware_selected(std::filesystem::path::string_type path) { void FlashUtilityView::firmware_selected(std::filesystem::path::string_type path) {
@ -179,4 +178,4 @@ void FlashUtilityView::focus() {
menu_view.focus(); menu_view.focus();
} }
} /* namespace ui */ } /* namespace ui */