From 181624daf115f58e62645bb43d4562ea50d056b5 Mon Sep 17 00:00:00 2001 From: not tre mann <24917424+zxkmm@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:56:55 +0800 Subject: [PATCH] lambda the flash util menu add item code (#1993) * lambda the flash util menu add code * clean up --- .../application/apps/ui_flash_utility.cpp | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/firmware/application/apps/ui_flash_utility.cpp b/firmware/application/apps/ui_flash_utility.cpp index a91a3951..27bccde0 100644 --- a/firmware/application/apps/ui_flash_utility.cpp +++ b/firmware/application/apps/ui_flash_utility.cpp @@ -26,7 +26,7 @@ namespace ui { -static const char16_t* firmware_folder = u"/FIRMWARE"; +static const std::filesystem::path firmware_path = u"/FIRMWARE"; // Firmware image validation 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}); - ensure_directory(firmware_folder); + ensure_directory(firmware_path); - for (const auto& entry : std::filesystem::directory_iterator(firmware_folder, u"*.bin")) { - auto filename = entry.path().filename(); - auto path = entry.path().native(); + auto add_firmware_items = [&]( + const std::filesystem::path& folder_path, + 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), - ui::Color::red(), - &bitmap_icon_temperature, - [this, path](KeyEvent) { - 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), + color, + &bitmap_icon_temperature, + [this, path](KeyEvent) { + this->firmware_selected(path); + }}); + } + }; - menu_view.add_item({filename.string().substr(0, max_filename_length), - ui::Color::purple(), - &bitmap_icon_temperature, - [this, path](KeyEvent) { - this->firmware_selected(path); - }}); - } + add_firmware_items(firmware_path, u"*.bin", ui::Color::red()); + add_firmware_items(firmware_path, u"*.tar", ui::Color::purple()); + + // add_firmware_items(user_firmware_folder,u"*.bin", ui::Color::purple()); } void FlashUtilityView::firmware_selected(std::filesystem::path::string_type path) { @@ -179,4 +178,4 @@ void FlashUtilityView::focus() { menu_view.focus(); } -} /* namespace ui */ +} /* namespace ui */ \ No newline at end of file