From 9fb0925e9a2f9653f0b90be2b5a5f700f702ed34 Mon Sep 17 00:00:00 2001 From: Nishi Date: Tue, 12 May 2026 09:51:49 +0900 Subject: [PATCH] dir loader --- src/dir.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ src/gui.c | 5 +++++ src/midas.h | 1 + 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/dir.c b/src/dir.c index c53fbd6..0c02027 100644 --- a/src/dir.c +++ b/src/dir.c @@ -10,6 +10,14 @@ struct direntry { char* path; }; +struct watchentry { + void* tv; + void* loading; + char* path; +}; + +static struct watchentry* watchlist = NULL; + static int sort_de(const void* _a, const void* _b) { struct direntry* a = (struct direntry*)_a; struct direntry* b = (struct direntry*)_b; @@ -20,15 +28,29 @@ static int sort_de(const void* _a, const void* _b) { return strcmp(a->d.d_name, b->d.d_name); } -static void dir_recursion(const char* path, const char* path2, void* tv) { +static void dir_recursion(const char* path, const char* path2, void* tv, int level, int notop) { PPR_DIR* dir; struct ppr_dirent* d; struct direntry* de = NULL; int i; - tv = MwTreeViewAdd(fileview, tv, NULL, path2); - if(path != path2) MwTreeViewSetOpened(fileview, tv, 0); + if(!notop) { + tv = MwTreeViewAdd(fileview, tv, NULL, path2); + if(path != path2) MwTreeViewSetOpened(fileview, tv, 0); + } if((dir = ppr_opendir(path)) != NULL) { + if(level == 0) { + struct watchentry we; + + we.tv = tv; + we.loading = MwTreeViewAdd(fileview, tv, NULL, "Loading..."); + we.path = MwStringDuplicate(path); + arrput(watchlist, we); + + ppr_closedir(dir); + return; + } + while((d = ppr_readdir(dir)) != NULL) { struct direntry new_de; @@ -39,10 +61,12 @@ static void dir_recursion(const char* path, const char* path2, void* tv) { #else new_de.path = ppr_strvacat(path, "/", d->d_name, NULL); #endif - new_de.d = *d; + new_de.d = *d; ppr_stat(new_de.path, &new_de.s); arrput(de, new_de); } + + ppr_closedir(dir); } if(de != NULL) { @@ -54,7 +78,9 @@ static void dir_recursion(const char* path, const char* path2, void* tv) { char* p = ppr_strvacat(de[i].d.d_name, PPR_S_ISDIR(de[i].s.st_mode) ? "/" : "", NULL); #endif - //dir_recursion(de[i].path, p, tv); + if(level > 0) { + dir_recursion(de[i].path, p, tv, level - 1, 0); + } free(p); @@ -74,5 +100,22 @@ void dir_scan(const char* dir) { realpath(dir, real); #endif - dir_recursion(real, real, NULL); + dir_recursion(real, real, NULL, 1, 0); +} + +void dir_tick(void) { + int i; + + for(i = 0; i < arrlen(watchlist); i++) { + if(MwTreeViewGetOpened(fileview, watchlist[i].tv)) { + MwTreeViewDelete(fileview, watchlist[i].loading); + + dir_recursion(watchlist[i].path, watchlist[i].path, watchlist[i].tv, 1, 1); + + free(watchlist[i].path); + arrdel(watchlist, i); + + i--; + } + } } diff --git a/src/gui.c b/src/gui.c index fa16ebd..a150e3c 100644 --- a/src/gui.c +++ b/src/gui.c @@ -107,6 +107,10 @@ static void MWAPI resize(MwWidget handle, void* user, void* client) { } } +static void tick(MwWidget handle, void* user, void* client) { + dir_tick(); +} + void gui_init(void) { MwRect rc; int w, h; @@ -146,6 +150,7 @@ void gui_init(void) { resize(window, NULL, NULL); MwAddUserHandler(window, MwNresizeHandler, resize, NULL); + MwAddUserHandler(window, MwNtickHandler, tick, NULL); MwTimeSleep(50); } diff --git a/src/midas.h b/src/midas.h index bd12581..ad66e3b 100644 --- a/src/midas.h +++ b/src/midas.h @@ -24,5 +24,6 @@ void gui_loop(void); /* dir.c */ void dir_scan(const char* dir); +void dir_tick(void); #endif