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 0000000..100594a Binary files /dev/null and b/assets-fx/img/opt_libs_bfile.png differ diff --git a/include/gintctl/assets.h b/include/gintctl/assets.h index 6d4b999..ab7c429 100644 --- a/include/gintctl/assets.h +++ 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); +}