From 742089704e24f9f90847eb57e92893d0018c07b3 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 5 May 2021 10:31:01 +0200 Subject: [PATCH] libs/bfile: add a simple BFile listing test --- CMakeLists.txt | 2 + assets-fx/img/opt_libs_bfile.png | Bin 0 -> 1320 bytes include/gintctl/assets.h | 1 + include/gintctl/libs.h | 3 + src/gintctl.c | 2 + src/libs/bfile.c | 94 +++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+) create mode 100644 assets-fx/img/opt_libs_bfile.png create mode 100644 src/libs/bfile.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 43a523d..a4f35bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ set(SOURCES src/gint/tlb.c src/gint/topti.c src/gint/usb.c + src/libs/bfile.c src/libs/justui.c src/libs/libimg.c src/libs/memory.c @@ -82,6 +83,7 @@ set(ASSETS_fx assets-fx/img/opt_gint_timers.png assets-fx/img/opt_gint_tlb.png assets-fx/img/opt_gint_usb.png + assets-fx/img/opt_libs_bfile.png assets-fx/img/opt_libs_jui.png assets-fx/img/opt_main.png assets-fx/img/opt_mem.png diff --git a/assets-fx/img/opt_libs_bfile.png b/assets-fx/img/opt_libs_bfile.png new file mode 100644 index 0000000000000000000000000000000000000000..100594a53644121b3ad92a02c2a11772fa007979 GIT binary patch literal 1320 zcmV+@1=sqCP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O1V>lI$i7{O?ob2uMOmIu2i|$_;Y-H1_Q5=H*r1 zCKWR?cx(_&cS~IRkKgn94Ht23S5@;Ctrc7~YH-Jmm(Odz`sW#ydjEc0^!lai>x=h$ z#;u^2=dab*b9p`g7}(xD0{!F#=?@d+y*__k*!p{6{tF^qrIxRke||HUXYOZry*AL$ zo=rVVTpwXDaDXMbr!_RgS8;E53p6jiOsZv-Sq9pqASNkEmDWX_k~S^$lO`}$-fZZZ zC(HfJ#W;9M5t4cuC7XmSabcOfMWkNBZ!C1L8~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++ b/include/gintctl/assets.h @@ -36,6 +36,7 @@ extern bopti_image_t img_opt_gint_timers, img_opt_gint_tlb, img_opt_gint_usb, + img_opt_libs_bfile, img_opt_libs_jui, img_opt_main, img_opt_mem, diff --git a/include/gintctl/libs.h b/include/gintctl/libs.h index f431077..54ab3b4 100644 --- a/include/gintctl/libs.h +++ b/include/gintctl/libs.h @@ -23,4 +23,7 @@ void gintctl_libs_libimg(void); /* gintctl_libs_justui(): Just User Interfaces */ void gintctl_libs_justui(void); +/* gintctl_libs_bfile(): BFile filesystem */ +void gintctl_libs_bfile(void); + #endif /* GINTCTL_LIBS */ diff --git a/src/gintctl.c b/src/gintctl.c index 9093823..6ab4621 100644 --- a/src/gintctl.c +++ b/src/gintctl.c @@ -83,6 +83,8 @@ struct menu menu_libs = { gintctl_libs_libimg, 0 }, { "JustUI widgets", gintctl_libs_justui, 0 }, + { "BFile filesystem", + gintctl_libs_bfile, 0 }, { NULL, NULL, 0 }, }}; diff --git a/src/libs/bfile.c b/src/libs/bfile.c new file mode 100644 index 0000000..3f9fa04 --- /dev/null +++ b/src/libs/bfile.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +/* Names and file informations (allocated on the stack) */ +static uint16_t (*test_names)[32][32]; +static struct BFile_FileInfo *test_infos; + +int explore_folder(uint16_t const *search, uint16_t names[32][32], + struct BFile_FileInfo infos[32]) +{ + /* Search descriptor */ + int sd = 0; + /* Number of files found */ + int found = 0; + + int rc = BFile_FindFirst(search, &sd, names[found], &infos[found]); + if(rc < 0) return 0; + + while(rc >= 0 && found < 32) { + found++; + rc = BFile_FindNext(sd, names[found], &infos[found]); + } + + BFile_FindClose(sd); + return found; +} + +static void table_gen(gtable *t, int row) +{ + char c1[48]={0}, c2[16]; + + for(int i = 0; i < 32 && (*test_names)[row][i]; i++) + c1[i] = (*test_names)[row][i]; + + sprintf(c2, "%d", test_infos[row].file_size); + gtable_provide(t, c1, c2); +} + +void gintctl_libs_bfile(void) +{ + /* Data for 32 files, each with 32 characters in the name */ + uint16_t names[32][32]; + struct BFile_FileInfo infos[32]; + + test_names = &names; + test_infos = infos; + + gtable *table = gtable_create(2, table_gen, NULL, NULL); + gtable_set_rows(table, 0); + gtable_set_column_titles(table, "Name", "Size"); + gtable_set_column_sizes(table, 3, 1); + gtable_set_font(table, _(&font_mini, dfont_default())); + jwidget_set_margin(table, 0, 2, 1, 2); + + gscreen *scr = gscreen_create2("BFile filesystem", &img_opt_libs_bfile, + "BFile access to storage memory", "@LIST;;;;;"); + gscreen_add_tabs(scr, table, table); + jscene_set_focused_widget(scr->scene, table); + + int key = 0; + while(key != KEY_EXIT) { + jevent e = jscene_run(scr->scene); + + if(e.type == JSCENE_PAINT) { + dclear(C_WHITE); + jscene_render(scr->scene); + dupdate(); + } + + key = 0; + if(e.type == JSCENE_KEY && e.key.type == KEYEV_DOWN) + key = e.key.key; + + if(key == KEY_F1) { + int rows = gint_world_switch(GINT_CALL(explore_folder, + u"\\\\fls0\\*", (void *)names, (void *)infos)); + gtable_set_rows(table, rows); + } + } + + test_names = NULL; + test_infos = NULL; + gscreen_destroy(scr); +}